python - Import package from unit test code -
i keep source code separate test code. so, have project organized this:
my_package/    module1.py    module2.py tests/   units/     test_a.py     test_b.py   perf_tests.py how should test_a.py import my_package?
note: i've googled (including so) , not satisfied answers:
- i don't want use setup.py, because want run development; testing, after all
- i don't want use symlinks or other hacks
- i've tried sys.path.append('../'),sys.path.append(os.path.realpath('../')). both result inimporterror: no module named my_package. perhaps similar can donepythonpath- syntax?
- i want write proper importstatement can find correct files
first have include __init__.py file inside folder my_package in order allow python recognize folder valid module. can create empty __init__.py file 1 line pass, example.
then, can in test_a.py:
import os bkp = os.getcwd() os.chdir(r'..\..') import my_package os.chdir(bkp) or use other options pythonpath or sys.path.append().
Comments
Post a Comment