Reputation: 13397
I have a tests/ directory with a single file that imports a number of 3rd party programs (pandas, etc). I'm running within a virtual env that has pandas installed.
pip freeze | grep pandas; cat requirements.txt | grep pandas
pandas==0.16.0
pandas==0.16.0
When I execute py.test I get the following error:
tests/test_pipeline.py:4: in <module>
import pandas as pd
E ImportError: No module named pandas
Which is the import pandas call within the test_pipeline.py file.
cat -n tests/test_pipeline.py | more
1 import sys
2 import os
3 import filecmp
4 import pandas as pd
Why is this an error when virtualenv is setup correctly? What am I doing incorrectly?
TIA
Upvotes: 1
Views: 645
Reputation: 5741
Do you have multiple Python versions installed? If so, py.test may be using a different version as the version which is used when running a script from the command line.
Eg. on my system, I have Python 3.5 on my PATH
, so:
>py.test --version
This is pytest version 2.8.1, imported from c:\program files\python 3.5\lib\site-packages\pytest.py
But if I run a python script from the command line: (this one prints platform.python_version()
)
>test.py
2.7.8
In fact, that version depends on what version I declare in my script, eg. if the first line of that script reads #! python3
, it will print 3.5.0
instead. (and Linux systems also look at that shebang line)
So make sure pandas is installed on the version you use when you run py.test.
Upvotes: 1