Source From Here
QuestionI have a project directory structure as follows (which I think is pretty standard):
- my_project
- setup.py
- mypkg
- __init__.py
- foo.py
- tests
- functional
- test_f1.py
- unit
- test_u1.py
In order to work around this, I have added a conftest.py file to my tests directory, containing the following code:
- import sys, os
- # Make sure that the application source directory (this directory's parent) is
- # on sys.path.
- here = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
- sys.path.insert(0, here)
How-To
As you say yourself py.test basically assumes you have the PYTHONPATH setup up correctly. There are several ways of achieving this:
The reason for py.test to behave this way is to make it easy to run the tests in a tests/ directory of a checkout against an installed package. If it would unconditionally add the project directory to the PYTHONPATH then this would not be possible anymore.
沒有留言:
張貼留言