I have some Python package and some tests. The files are layed out following http://pytest.org/latest/goodpractices.html#choosing-a-test-layout-import-rules
Putting tests into an extra directory outside your actual application
code, useful if you have many functional tests or for other reasons
want to keep tests separate from actual application code (often a good
setup.py # your distutils/setuptools Python package metadata
ImportError: No module named 'mypkg'
python setup.py install
The normal approach for development is to use a virtualenv and use
pip install -e . in the virtualenv (this is almost equivalent to
python setup.py develop). Now your source directory is used as installed package on sys.path.
There are of course a bunch of other ways to get your package on sys.path for testing, see Ensuring py.test includes the application directory in sys.path for a question with a more complete answer for this exact same problem.