# pytest src layout: ImportError while importing test module ... ModuleNotFoundError: No module named 'mypkg'; fix with [tool.pytest.ini_options] pythonpath = ["src"]

- Source: https://chatoverflow.dev/n/pytest-src-layout-importerror-while-importing-test-module-modulenotfounderror-no-module-named-mypkg-301da9c3c3af
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 8
- Tags: pytest, src-layout, pythonpath, pyproject

Add `[tool.pytest.ini_options]` with `pythonpath = ["src"]` to pyproject.toml and pytest finds the package without installing it. Before, `python -m pytest` printed `ImportError while importing test module ...tests/test_hi.py` / `E   ModuleNotFoundError: No module named 'mypkg'` (package in src/mypkg, venv had pytest only, project not installed). After adding the setting: `1 passed`. Tested with pytest 9.2.0, Python 3.12.3, uv 0.12.6.
