Question: Module discovery for a new module
bearrito opened this issue · comments
Hello,
I'm working on a new module for https://nats.io/
How does module discovery work?
For instance VSCode test discovery is unhappy with the new module
_______________ ERROR collecting modules/nats/tests/test_nats.py _______________
ImportError while importing test module '/workspaces/testcontainers-python/modules/nats/tests/test_nats.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
/usr/local/lib/python3.11/importlib/__init__.py:126: in import_module
return _bootstrap._gcd_import(name[level:], package, level)
modules/nats/tests/test_nats.py:1: in <module>
from testcontainers.nats import NatsContainer
E ModuleNotFoundError: No module named 'testcontainers.nats'
=========================== short test summary info ============================
ERROR modules/nats/tests/test_nats.py
!!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!
===================== 44 tests collected, 1 error in 0.97s =====================
Thinking this is a VScode issue I tried via just poetry
(testcontainers-_53phrdA-py3.11) vscode ➜ /workspaces/testcontainers-python (feature/nats) $ poetry run pytest -v --cov=testcontainers.$* modules/nats/tests
===================================================== test session starts ======================================================
platform linux -- Python 3.11.8, pytest-7.4.3, pluggy-1.4.0 -- /home/vscode/.cache/pypoetry/virtualenvs/testcontainers-_53phrdA-py3.11/bin/python
cachedir: .pytest_cache
rootdir: /workspaces/testcontainers-python
configfile: pyproject.toml
plugins: cov-4.1.0, anyio-4.3.0
collected 0 items / 1 error
/home/vscode/.cache/pypoetry/virtualenvs/testcontainers-_53phrdA-py3.11/lib/python3.11/site-packages/coverage/inorout.py:503: CoverageWarning: Module testcontainers. was never imported. (module-not-imported)
self.warn(f"Module {pkg} was never imported.", slug="module-not-imported")
/home/vscode/.cache/pypoetry/virtualenvs/testcontainers-_53phrdA-py3.11/lib/python3.11/site-packages/coverage/control.py:885: CoverageWarning: No data was collected. (no-data-collected)
self._warn("No data was collected.", slug="no-data-collected")
WARNING: Failed to generate report: No data to report.
/home/vscode/.cache/pypoetry/virtualenvs/testcontainers-_53phrdA-py3.11/lib/python3.11/site-packages/pytest_cov/plugin.py:312: CovReportWarning: Failed to generate report: No data to report.
warnings.warn(CovReportWarning(message))
============================================================ ERRORS ============================================================
_______________________________________ ERROR collecting modules/nats/tests/test_nats.py _______________________________________
ImportError while importing test module '/workspaces/testcontainers-python/modules/nats/tests/test_nats.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
/usr/local/lib/python3.11/importlib/__init__.py:126: in import_module
return _bootstrap._gcd_import(name[level:], package, level)
modules/nats/tests/test_nats.py:1: in <module>
from testcontainers.nats import NatsContainer
E ModuleNotFoundError: No module named 'testcontainers.nats'
I think my directory structure is correct
Presumably the pyproject.toml
needs to be modified to reflect the new module. Doing that by hand (following other packages) gives
(testcontainers-_53phrdA-py3.11) vscode ➜ /workspaces/testcontainers-python (feature/nats) $ poetry lock --no-update
Resolving dependencies... (0.2s)
Because testcontainers depends on nats (*) which doesn't match any versions, version solving failed.
I've never used poetry to create extras/modules so I'm not sure if there is a poetry command I should be executing.
Sorted this out. You can see what I did here - #439
Maybe there is a poetry way of doing this but I just added fields to the pyproject.toml