Sys.path Including Py.test Rootdir To Make Tests Import Relative To Project Root
I'm having problems with pytest not including my projects rootdir in sys.path list. Instead it is including the directory where the tests are located by default. Here is my project
Solution 1:
I use a conftest.py that appends the package path (relative to the conftest.py file) to sys.path so the package can be imported. Something like this:
# contents of conftest.py
import sys
from os.path import abspath, dirname
package_path = abspath(dirname(dirname(__file__)))
sys.path.insert(0, package_path)
You would then put this file in the tests directory. The conftest.py file will get run before any thing else by default, so the other tests will be able to import mypackage.
Another, probably better, approach is to add a setup.py and follow the advice given here.
Post a Comment for "Sys.path Including Py.test Rootdir To Make Tests Import Relative To Project Root"