stale-waitress-56895
05/23/2025, 4:57 PMpython_tests
, if someone could help me get unblocked. I have this very simple setupstale-waitress-56895
05/23/2025, 4:57 PM#BUILD
python_sources(
name="src",
resolve="cuspy",
sources=["src/**/*.py"],
dependencies=[
":reqs",
],
)
python_requirements(
name="reqs",
resolve="cuspy",
source="pyproject.toml",
)
python_tests(
name="tests",
sources=[
"tests/test_*.py",
],
resolve="cuspy",
dependencies=[
":src",
],
)
stale-waitress-56895
05/23/2025, 4:58 PMdef test_env_file():
from cuspy_datahold.config import config
assert config.s3.access_key is not None
stale-waitress-56895
05/23/2025, 4:58 PMdef test_env_file():
> from cuspy_datahold.config import config
E ModuleNotFoundError: No module named 'cuspy_datahold'
libraries/cuspy_datahold/tests/test_config.py:2: ModuleNotFoundError
- generated xml file: /home/coder/.cachelibraries.cuspy_datahold.tests.test_config.py@tests.xml -
stale-waitress-56895
05/23/2025, 4:59 PM[pytest]
install_from_resolve = "cuspy"
stale-waitress-56895
05/23/2025, 5:00 PMpants test libraries/cuspy_datahold/tests/test_config.py
16:53:23.81 [INFO] Initializing scheduler...
16:53:26.18 [INFO] Scheduler initialized.
16:53:28.26 [INFO] Canceled: Building 23 requirements for requirements.pex from the third-party/python/cuspy.lock resolve: aioboto3, click, elasticsearch[async], flytekit, microsoft-python-type-stubs@ git+<https://github.com/micro>... (258 characters truncated)
16:53:32.02 [INFO] Completed: Building pytest.pex
16:53:32.02 [INFO] Completed: Building 23 requirements for requirements.pex from the third-party/python/cuspy.lock resolve: aioboto3, click, elasticsearch[async], flytekit, microsoft-python-type-stubs@ git+<https://github.com/micro>... (258 characters truncated)
16:53:33.05 [INFO] Completed: Building local_dists.pex
16:53:35.47 [INFO] Completed: Building pytest_runner.pex
16:53:35.93 [ERROR] Completed: Run Pytest - libraries/cuspy_datahold/tests/test_config.py:../tests - failed (exit code 1).
============================= test session starts ==============================
platform linux -- Python 3.12.3, pytest-8.3.5, pluggy-1.6.0
rootdir: /home/coder/.cachelibraries/cuspy_datahold
configfile: pytest.ini
plugins: cov-6.1.1, asyncio-0.26.0
asyncio: mode=Mode.AUTO, asyncio_default_fixture_loop_scope=function, asyncio_default_test_loop_scope=function
collected 1 item
libraries/cuspy_datahold/tests/test_config.py F
WARNING: Failed to generate report: No data to report.
[100%]
=================================== FAILURES ===================================
________________________________ test_env_file _________________________________
def test_env_file():
> from cuspy_datahold.config import config
E ModuleNotFoundError: No module named 'cuspy_datahold'
libraries/cuspy_datahold/tests/test_config.py:2: ModuleNotFoundError
- generated xml file: /home/coder/.cachelibraries.cuspy_datahold.tests.test_config.py@tests.xml -
================================ tests coverage ================================
_______________ coverage: platform linux, python 3.12.3-final-0 ________________
=========================== short test summary info ============================
FAILED libraries/cuspy_datahold/tests/test_config.py::test_env_file - ModuleNotFoundError: No module named 'cuspy_datahold'
============================== 1 failed in 0.10s ===============================
/home/coder/.cache/pants/named_caches/pex_root/venvs/1/s/6d70758f/venv/lib/python3.12/site-packages/coverage/inorout.py:509: CoverageWarning: Module cuspy_datahold was never imported. (module-not-imported)
self.warn(f"Module {pkg} was never imported.", slug="module-not-imported")
/home/coder/.cache/pants/named_caches/pex_root/venvs/1/s/6d70758f/venv/lib/python3.12/site-packages/coverage/control.py:915: CoverageWarning: No data was collected. (no-data-collected)
self._warn("No data was collected.", slug="no-data-collected")
/home/coder/.cache/pants/named_caches/pex_root/venvs/1/s/6d70758f/venv/lib/python3.12/site-packages/pytest_cov/plugin.py:336: CovReportWarning: Failed to generate report: No data to report.
warnings.warn(CovReportWarning(message), stacklevel=1)
ā libraries/cuspy_datahold/tests/test_config.py:../tests failed in 0.43s.
fast-nail-55400
05/23/2025, 5:01 PMsrc
set as a source root? https://www.pantsbuild.org/stable/reference/subsystems/source#root_patternsadorable-psychiatrist-59834
05/23/2025, 5:02 PMfast-nail-55400
05/23/2025, 5:02 PMpants.toml
?fast-nail-55400
05/23/2025, 5:04 PMlibraries/cuspy_datahold/tests/test_config.py
, you would need to set src/libraries
(assuming that is the parent path) as a source root.stale-waitress-56895
05/23/2025, 5:05 PM[GLOBAL]
pants_version = "2.25.1"
colors = true
backend_packages = [
"pants.backend.shell",
"pants.backend.python",
"pants.backend.python.typecheck.mypy",
"pants.backend.docker",
"pants.backend.experimental.python",
"pants.backend.experimental.python.lint.ruff.check",
"pants.backend.experimental.python.lint.ruff.format",
]
[python]
interpreter_constraints = ["CPython>=3.10,<3.13"]
enable_resolves = true
default_resolve = "default"
[pytest]
install_from_resolve = "cuspy"
[python.resolves]
default = "third-party/python/default.lock"
cuspy = "third-party/python/cuspy.lock"
[python-infer]
imports = false
stale-waitress-56895
05/23/2025, 5:05 PMpants roots | grep datahold
libraries/cuspy_datahold/src
fast-nail-55400
05/23/2025, 5:07 PMpants dependencies TARGET
to see.
⢠Are all of the sources present in the execution sandbox? Run your test with --keep-sandboxes=on_failure
and then inspect the preserved sandbox. The path will be printed out in the log.fast-nail-55400
05/23/2025, 5:09 PMfind . -type f
would be useful.)fast-nail-55400
05/23/2025, 5:10 PMpants.toml
?
[source]
root_patterns = ["src", "libraries"]
fast-nail-55400
05/23/2025, 5:12 PMcuspy_datahold.src.foo
and not cuspy_datahold.foo
stale-waitress-56895
05/23/2025, 5:14 PMfast-nail-55400
05/23/2025, 5:14 PMstale-waitress-56895
05/23/2025, 5:14 PMfast-nail-55400
05/23/2025, 5:15 PMcuspy_datahold.foo
module, then its file would live at library/cusp_datahold/src/cusp_datahold/foo.py
fast-nail-55400
05/23/2025, 5:15 PMfast-nail-55400
05/23/2025, 5:16 PMPYTHONPATH
(that is an oversimpification but it is a somewhat apt comarison)stale-waitress-56895
05/23/2025, 5:20 PMstale-waitress-56895
05/23/2025, 5:20 PMstale-waitress-56895
05/23/2025, 5:21 PMfast-nail-55400
05/23/2025, 6:27 PM--keep-sandoxes=on_failure
to inspect the actual execution sandbox used for the failing test,.stale-waitress-56895
05/25/2025, 11:05 AMlibraries/cuspy_datahold/
āāā BUILD
āāā pyproject.toml
āāā src
ā āāā cuspy_datahold
ā āāā examples
ā ā āāā cow
ā ā ā āāā __init__.py
ā ā āāā flyte
ā ā ā āāā my_project
ā ā ā āāā workflows
ā ā ā āāā __init__.py
ā ā āāā omat24
ā ā ā āāā __init__.py
ā ā āāā pymatgen
ā ā āāā v0
ā ā āāā __init__.py
ā āāā __init__.py
ā āāā models
ā āāā __init__.py
āāā tests
āāā cuspy_datahold
ā āāā __init__.py
āāā __init__.py
Notice the BUILD
file at the root of this library, and the nested src/cuspy_datahold
code source.
my BUILD file includes the following
python_sources(
name="src",
sources=["src/**/*.py"],
resolve="cuspy",
dependencies=[
":reqs",
],
)
and so the tests use it this way
python_tests(
name="tests",
sources=["tests/**/test_*.py"],
resolve="cuspy",
dependencies=[
":src",
":reqs"
],
)
However, with that, I get
ModuleNotFoundError: No module named 'cuspy_datahold'
I guess because with this configuration, the code becomes visible with
src.cuspy_datahold
?
This is weird because my pants roots actually shows
pants roots | grep datahold
libraries/cuspy_datahold/src
So I thought... this means it's going to be picked up as cuspy_datahold
stale-waitress-56895
05/25/2025, 11:07 AMlibraries/cuspy_datahold/src
with the following content:
python_sources(
sources=["**/*.py"],
resolve="cuspy",
)
and then the tests in ``libraries/cuspy_datahold/BUILD`` can be configured as such
python_tests(
name="tests",
sources=["tests/**/test_*.py"],
resolve="cuspy",
dependencies=[
"./src", # uses the BUILD in the src subdirectory
":reqs"
],
)
stale-waitress-56895
05/25/2025, 11:08 AM