feat(WIP): allow pytest deps to come from target resolve#22835
Draft
lecardozo wants to merge 2 commits intopantsbuild:mainfrom
Draft
feat(WIP): allow pytest deps to come from target resolve#22835lecardozo wants to merge 2 commits intopantsbuild:mainfrom
lecardozo wants to merge 2 commits intopantsbuild:mainfrom
Conversation
5035b26 to
903daaa
Compare
lecardozo
commented
Oct 29, 2025
Comment on lines
+299
to
+312
| pytest_req_strings = pytest.requirements if pytest.requirements else pytest.default_requirements | ||
| pytest_requirements = PexRequirements( | ||
| pytest_req_strings, | ||
| from_superset=Resolve(target_resolve, use_entire_lockfile=False), | ||
| description_of_origin="pytest requirements from target resolve", | ||
| ) | ||
| pytest_pex_get = create_pex( | ||
| PexRequest( | ||
| output_filename="pytest_from_target_resolve.pex", | ||
| internal_only=True, | ||
| requirements=pytest_requirements, | ||
| interpreter_constraints=interpreter_constraints, | ||
| ) | ||
| ) |
Author
There was a problem hiding this comment.
author's note: maybe this logic would be better close to PythonToolBase.pex_requirements
Kept it here initially because it feels like this behavior is only desirable for pytest specifically not all python tools due to it's nature as both a library and a tool
Contributor
There was a problem hiding this comment.
We can always move it later, and for now this keeps the blast radius more contained.
benjyw
reviewed
Nov 8, 2025
Contributor
benjyw
left a comment
There was a problem hiding this comment.
This looks good, thanks for the contribution!
How have you tested it? It would be good to add some testing in pytest_runner_test.py.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Context
Currently, the pytest runner creates an environment composed by a mix of the
python_testdependencies and the pytest dependencies that are needed for the test to properly run. In cases which a third-party dependency is contained both the python_test dependency as well as pytest with potentially different versions (since they come from independent resolves), this can lead to inconsistencies between production and testing environment, which is undesirable.Related issues and threads
Potential solution (work in progress)
One way to avoid that is to make sure pytest dependencies come from the same resolve as the one used by the python_test target. In cases where the monorepo has a single resolve, this can already be solved with the
pytest.install_from_resolvesetting. However, in cases where the monorepo contains more than one resolve, there's currently no way to solve that.This PR introduces
pytest.install_from_target_resolve: BoolOptionsetting that, when set true, ignores the pytest resolve configuration and expects test dependencies to come from the target resolve. This ensures all dependencies are aligned across different execution environments.Potential problems
Since we are ignoring pytest dependencies, we need to make sure they are included on the list of dependencies before building the venv, otherwise this won't work.this should be addressed on 903daaa