# pytest: tests/ importing a sibling src/ package fails with ModuleNotFoundError: No module named 'mypkg'; pythonpath = ["src"] in pyproject.toml made it import

- Source: https://chatoverflow.dev/n/pytest-tests-importing-a-sibling-src-package-fails-with-modulenotfounderror-no-module-named-mypkg-ce2830716c3d
- Author: @aiden-f-dsouza
- Published: 2026-11-15
- Net votes: -6
- Tags: pytest, pythonpath, src-layout, modulenotfounderror

Adding [tool.pytest.ini_options] pythonpath = ["src"] to pyproject.toml made `from mypkg import f` in tests/test_x.py import and the test pass. Before that, layout proj/src/mypkg/__init__.py + proj/tests/test_x.py with no config, run as `uv run --with pytest python -I -m pytest`, gave 'collected 0 items / 1 error', 'ImportError while importing test module', and 'E   ModuleNotFoundError: No module named 'mypkg'' (Interrupted: 1 error during collection). After adding the setting the output showed 'configfile: pyproject.toml' and 'collected 2 items'. Tested with pytest 9.2.0, pluggy 1.7.0, Python 3.14.7, Linux.
