plain-monkey-49051
04/29/2022, 10:21 PM./pants test
Adding BUILD files a little at a time since I hit a bug when `tailor`ing. the whole project, so initially I have things configured to run just one test file. When I run ./pants filter --target-type=python_test ::
I see the output I expect since this is the directory where I added a BUILD file with python_test(…):
sundial_utils/tests/sundial_utils/analytics:analytics
But if I run ./pants test
the test file inside that analytics subdirectory (named test_rando.py
) is not found, despite the fact that its name conforms to the glob pattern described in the “Unmatched globs” error message:
Unmatched globs from sundial_utils/src/sundial_utils/analytics:analytics's `sources` field: ["sundial_utils/src/sundial_utils/analytics/*_test.py", "sundial_utils/src/sundial_utils/analytics/test_*.py", "sundial_utils/src/sundial_utils/analytics/tests.py"]
Not sure what to try to get this working.witty-crayon-22786
04/29/2022, 10:32 PMplain-monkey-49051
04/29/2022, 10:46 PMplain-monkey-49051
04/29/2022, 11:05 PMsrc
and tests
directories for each project in the monorepo:
repo
projectA
src
projectA
... packages ...
tests
projectA
... packages ...
projectB
src
projectB
... packages ...
tests
projectB
... packages ...
projectC
src
projectC
... packages ...
tests
projectC
... packages ...
So, lots of nesting and use of subdirectories for namespacing imports. My pants.toml looks like this to configure every src
and tests
directory as roots:
[GLOBAL]
pants_version = "2.10.0"
use_deprecated_python_macros = false
backend_packages = [
"pants.backend.python"
]
[source]
root_patterns = [
"src",
"tests"
]
[anonymous-telemetry]
enabled = false
The reason I mention the layout is that the “unmatched globs” error message shows paths from the monorepo root not the source roots that I configured.plain-monkey-49051
04/29/2022, 11:07 PMwitty-crayon-22786
04/29/2022, 11:08 PMhappy-kitchen-89482
04/29/2022, 11:10 PMwitty-crayon-22786
04/29/2022, 11:10 PMwitty-crayon-22786
04/29/2022, 11:10 PMwitty-crayon-22786
04/29/2022, 11:10 PMpython_tests(
name="sundial_utils_tests"
)
at the “root” of something, there would need to be files in the same directory in order for it to do anythinghappy-kitchen-89482
04/29/2022, 11:10 PMplain-monkey-49051
04/29/2022, 11:11 PMwitty-crayon-22786
04/29/2022, 11:11 PMtailor
working (https://github.com/pantsbuild/pants/issues/15276) is probably the best path, because manually creating BUILD files is… so last year 😃happy-kitchen-89482
04/29/2022, 11:12 PMpython_tests()
in the source root and then also a python_tests()
in a subdirectory of that source root?plain-monkey-49051
04/29/2022, 11:13 PMhappy-kitchen-89482
04/29/2022, 11:14 PMhappy-kitchen-89482
04/29/2022, 11:14 PMpython_tests(
name="sundial_utils_tests"
)
ishappy-kitchen-89482
04/29/2022, 11:14 PMwitty-crayon-22786
04/29/2022, 11:14 PMBUILD
file from https://github.com/pantsbuild/pants/issues/15276 ?witty-crayon-22786
04/29/2022, 11:15 PMplain-monkey-49051
04/29/2022, 11:16 PMpython_requirements()
witty-crayon-22786
04/29/2022, 11:19 PMpython_sources
and python_tests
targets generated: in the common case, 0 hand edits should be necessaryplain-monkey-49051
04/29/2022, 11:22 PMhappy-kitchen-89482
04/29/2022, 11:23 PMplain-monkey-49051
04/29/2022, 11:23 PMhappy-kitchen-89482
04/29/2022, 11:23 PMhappy-kitchen-89482
04/29/2022, 11:23 PMplain-monkey-49051
04/29/2022, 11:23 PM./pants test
happy-kitchen-89482
04/29/2022, 11:24 PMhappy-kitchen-89482
04/29/2022, 11:24 PMwitty-crayon-22786
04/29/2022, 11:25 PMhappy-kitchen-89482
04/29/2022, 11:25 PM./pants test
alone indeed does nothing (perhaps unintuitively)happy-kitchen-89482
04/29/2022, 11:25 PMhappy-kitchen-89482
04/29/2022, 11:25 PM./pants test path/to/foo_test.py
?plain-monkey-49051
04/29/2022, 11:29 PMpytest
from the root: the test suite runs fine.plain-monkey-49051
04/29/2022, 11:30 PMplain-monkey-49051
04/29/2022, 11:33 PMwitty-crayon-22786
04/29/2022, 11:36 PMplain-monkey-49051
04/29/2022, 11:36 PMimport-mode = "importlib"
which is only supported by pytest >= 7.0 and it looks like Pants is running an older version.plain-monkey-49051
04/30/2022, 12:19 AMwitty-crayon-22786
04/30/2022, 12:30 AMpython_requirements
macro creates targets for the requirements.txt
, and then dependency inference picks those up automatically.witty-crayon-22786
04/30/2022, 12:30 AM