Fix pytest ModuleNotFoundError: No module named 'src'#5
Fix pytest ModuleNotFoundError: No module named 'src'#5
Conversation
…ject.toml Agent-Logs-Url: https://github.com/DaScient/Energy/sessions/0e33b44b-4557-4706-be2d-6ccc5b4fa16d Co-authored-by: DaScient <25983786+DaScient@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Adds pytest configuration to ensure the repository root is added to sys.path during test runs, resolving ModuleNotFoundError: No module named 'src' during collection in environments that don’t install the project as a package.
Changes:
- Add
[tool.pytest.ini_options]topyproject.toml. - Configure
pythonpath = ["."]sosrc.*imports resolve under pytest.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| where = ["src"] | ||
|
|
||
| [tool.pytest.ini_options] | ||
| pythonpath = ["."] |
There was a problem hiding this comment.
pythonpath = ["."] makes import src.* work when running tests from the repo checkout, but it also cements src as an importable top-level package. This conflicts with the existing setuptools packages.find where = ["src"] (src-layout), where installed code would typically be imported as signal_processing... / dascient_suite... (without the src. prefix). Consider aligning the import strategy by either (a) switching pytest pythonpath to ["src"] and updating tests to import the real packages, or (b) adjusting the packaging config to actually ship a top-level src package if that’s the intended public import path.
| pythonpath = ["."] | |
| pythonpath = ["src"] |
Agent-Logs-Url: https://github.com/DaScient/Energy/sessions/e462099f-0a38-43a1-96b8-5e2c435823d3 Co-authored-by: DaScient <25983786+DaScient@users.noreply.github.com>
Agent-Logs-Url: https://github.com/DaScient/Energy/sessions/26c5a0d7-247d-4ba1-bab9-754564975df9 Co-authored-by: DaScient <25983786+DaScient@users.noreply.github.com>
Agent-Logs-Url: https://github.com/DaScient/Energy/sessions/26c5a0d7-247d-4ba1-bab9-754564975df9 Co-authored-by: DaScient <25983786+DaScient@users.noreply.github.com>
Tests in
tests/test_hodgkin_huxley_dynamics.pyfail to collect becausesrcis not onsys.pathwhen pytest runs — despite the project root containing thesrc/package directory.Change
Added
[tool.pytest.ini_options]topyproject.tomlwithpythonpath = ["."]to instruct pytest to add the project root tosys.path:This makes
from src.signal_processing.hodgkin_huxley_model import HodgkinHuxleyModelresolvable without modifying test files or the package structure.