I created this as an answer to your question and my own confusion. I hope this helps. Pay attention to PYTHONPATH on the py.test command line and in tox.ini .
An example project is here , as well as below:
mymodule.py :
import boto3 def stuff(): print "Yep!"
tests/text_syntax_errors.py :
import boto3 import mymodule
tox.ini :
[tox] skipsdist = True envlist = py27 [flake8] max-line-length = 119 [testenv] deps= -r{toxinidir}/requirements.txt commands=py.test setenv = PYTHONPATH = {toxinidir}
requirements.txt :
boto3 pytest
From my README.md :
How to run these examples
My initial motivation for testing my code was that I made a mistake with the imported module in the script that I wrote to work.
If you edit mymodule.py and delete b with " boto3 ", you will see that the commands below do not work. And this is good. Similarly, if you want to see the actual test fail, just edit tests/test_syntax_errors.py and change 1 == 1 to 1 == 0 .
py.test
mbp0 pytest_test[master+*] $ PYTHONPATH=. py.test ========================== test session starts ========================== platform darwin -- Python 2.7.11, pytest-2.9.2, py-1.4.31, pluggy-0.3.1 rootdir: /Users/jmacdonald/w/pytest_test, inifile: collected 1 items tests/test_syntax_errors.py . ======================= 1 passed in 0.11 seconds ======================== mbp0 pytest_test[master+*] $
toxicodendron
mbp0 pytest_test[master+*] $ tox py27 installed: boto3==1.3.1,botocore==1.4.37,docutils==0.12,futures==3.0.5,jmespath==0.9.0,py==1.4.31,pytest==2.9.2,python-dateutil==2.5.3,six==1.10.0 py27 runtests: PYTHONHASHSEED='713732044' py27 runtests: commands[0] | py.test ========================== test session starts ========================== platform darwin -- Python 2.7.11, pytest-2.9.2, py-1.4.31, pluggy-0.3.1 rootdir: /Users/jmacdonald/w/pytest_test, inifile: collected 1 items tests/test_syntax_errors.py . ======================= 1 passed in 0.11 seconds ======================== ________________________________ summary ________________________________ py27: commands succeeded congratulations :) mbp0 pytest_test[master+*] $