You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
poly check --strict false positive for a pytest plugin聽#400
$ poly check --strict
馃攷 Is `e2e_test` needed in`e2e_test_base_project`?
where e2e_test_base_project is a project that runs e2e tests implemented on top of pytest.
It uses custom ns.e2e_test pytest plugin that is defined as a polylith component
(just some shared pytest fixtures between different e2e test projects).
The project does not import ns.e2e_test code explicitly. It is done by pytest itself, triggered by:
pytest_plugins= [
"ns.e2e_test",
]
in conftest.py inside e2e_test_base polylith base which is the base for the e2e_test_base_project project.
Is there a way to suppress the poly check warning?
Hi @zed, is the component added as a brick in the project? If it's not used as a brick in the code then maybe it can be added to the project in a different way? This is how you can do it in Hatch.
As an alternative, you could do an import of it in code, and silence the linter with an "ignore".
I've considered the explicit dummy import ns.e2e_test but it might
mess with pytest's expected order (first it loads all conftest and
only then pytest_plugins recursively) and therefore it might have
unintended side-effects.
I've tried:
[tool.hatch.build.targets.sdist]
include = [
"../../components/ns/e2e_test/"
]
but it does not include anything -- likely, because the path is outside the project root.
force-include
makes the files available in the distribution:
I'll think about if there's a simple way to solve this with the tooling, I think your use case should be supported.
Other: This should only happen when running the check command in --strict mode. Maybe you want to keep doing that, but it is also an alternative to just run poly check.
How do you run the tests, and how does the project fit in? I would like to reproduce this problem. I have the test dependencies in the root pyproject.toml, and run the tests in the virtual environment created for the repo root. If I understand it correctly, you have a Polylith project that contains tests?
Using monorepo's virtualenv environment during developement of the tests themselves
Using project (projects/e2e_test_base_project) specific
virtualenv environment (or as uv tool install-ed version).
In both cases, the same command may be used (from different working directories):
uv run python -m ns.e2e_test_base
It picks up the desired venv automatically.
There is no issue with importing ns.e2e_test in the monorepo's
virtualenv because the development environment (repo's /pyproject.toml)
depends on all bricks including ns/e2e_test.
There is import error if ns/e2e_test is removed from the
project-specific (projects/e2e_test_base_project/pyproject.toml) [tool.polylith.bricks] section.
I've made a mistake in the previous comment. force-include does help
with the import error too i.e., it is a viable workaround option. The
issue was in the interaction between uv run and uv-dynamic-versioning for the project.
Great that using force-include works, and thank you for explaining more about your setup! I think it makes sense that the tool reports on the unused brick in --strict mode. That's also only an information to highlight that bricks could be removed from the project. I see a possible "skip" or "ignore" option or config, but I think that could cause other problems if forgetting to update configuration. Also, the poly check command won't exit with a fail code as with missing bricks or deps.
It makes both pytest and poly check happy. No import at runtime -- no undesirable side-effects.
e2e_test_base_project continues to be dependent on ns/e2e_test brick (good).
I've might have been too hasty with the force-include version. uv build . packages ns/e2e_test files but it does not translate into
working uv run python -m ns.e2e_test_base command in projects/e2e_test_base_project dir in a clean environment (uv tool install-ed version works though).
Activity
DavidVujic commentedon Nov 14, 2025
Hi @zed, is the component added as a brick in the project? If it's not used as a brick in the code then maybe it can be added to the project in a different way? This is how you can do it in Hatch.
As an alternative, you could do an import of it in code, and silence the linter with an "ignore".
zed commentedon Nov 14, 2025
Yes,
ns/e2e_testis added as a brick toe2e_test_base_project.If I remove it from the .bricks section, I get:
The traceback shows that pytest uses the ordinary builtin
__import__function
to import it.
I've considered the explicit dummy
import ns.e2e_testbut it mightmess with pytest's expected order (first it loads all conftest and
only then pytest_plugins recursively) and therefore it might have
unintended side-effects.
I've tried:
but it does not include anything -- likely, because the path is outside the project root.
force-includemakes the files available in the distribution:
but it does not fix the import error unless
is also present. It reintroduces the warning from
poly check.As a workaround, I use the explicit import (no side-effects so far in my case):
DavidVujic commentedon Nov 14, 2025
I'll think about if there's a simple way to solve this with the tooling, I think your use case should be supported.
Other: This should only happen when running the check command in
--strictmode. Maybe you want to keep doing that, but it is also an alternative to just runpoly check.DavidVujic commentedon Nov 15, 2025
How do you run the tests, and how does the project fit in? I would like to reproduce this problem. I have the test dependencies in the root pyproject.toml, and run the tests in the virtual environment created for the repo root. If I understand it correctly, you have a Polylith project that contains tests?
zed commentedon Nov 15, 2025
There are 2 main ways to run the tests:
projects/e2e_test_base_project) specificvirtualenv environment (or as
uv tool install-ed version).In both cases, the same command may be used (from different working directories):
It picks up the desired venv automatically.
There is no issue with importing
ns.e2e_testin the monorepo'svirtualenv because the development environment (repo's
/pyproject.toml)depends on all bricks including
ns/e2e_test.There is import error if
ns/e2e_testis removed from theproject-specific (
projects/e2e_test_base_project/pyproject.toml)[tool.polylith.bricks]section.I've made a mistake in the previous comment.
force-includedoes helpwith the import error too i.e., it is a viable workaround option. The
issue was in the interaction between
uv runanduv-dynamic-versioningfor the project.DavidVujic commentedon Nov 15, 2025
Great that using
force-includeworks, and thank you for explaining more about your setup! I think it makes sense that the tool reports on the unused brick in--strictmode. That's also only an information to highlight that bricks could be removed from the project. I see a possible "skip" or "ignore" option or config, but I think that could cause other problems if forgetting to update configuration. Also, thepoly checkcommand won't exit with a fail code as with missing bricks or deps.DavidVujic commentedon Nov 15, 2025
I was thinking about what can be done in the pytest files (such as
conftest.py). Would this work? (I haven't tested this out, just an idea)zed commentedon Nov 16, 2025
At the moment, I've settled on keeping
ns/e2e_testas a brick and modifyingconftest.py:It makes both
pytestandpoly checkhappy. No import at runtime -- no undesirable side-effects.e2e_test_base_projectcontinues to be dependent onns/e2e_testbrick (good).I've might have been too hasty with the
force-includeversion.uv build .packagesns/e2e_testfiles but it does not translate intoworking
uv run python -m ns.e2e_test_basecommand inprojects/e2e_test_base_projectdir in a clean environment (uv tool install-ed version works though).DavidVujic commentedon Nov 16, 2025
Nice! I'll transfer this to a Q&A discussion, to keep it as documentation.