test(pytest): support python_versions in pytest_test macro - #4064
Merged
rickeylev merged 5 commits intoAug 17, 2026
Conversation
Running pytest tests across multiple Python versions previously required manually declaring individual targets for each version. Add the `pytest_multipy_test` macro in `tests/support/pytest_test` which accepts `python_versions` and generates version-specific `pytest_test` targets with smart name formatting while aggregating them under a root `test_suite`.
Update pytest_multipy_default_test to test Python 3.14 and 3.13, and wrap the fail error message in pytest_test.bzl to adhere to 80-column line length.
rickeylev
marked this pull request as ready for review
August 16, 2026 23:39
aignas
approved these changes
Aug 17, 2026
Comment on lines
+36
to
+39
| python_versions = [ | ||
| "3.14", | ||
| "3.13", | ||
| ], |
Collaborator
There was a problem hiding this comment.
I really like this - it is quite important to have this sort of thing. Could we create pytest_test macro and accept python_version or python_versions attributes which would do the underlying wiring by themselves?
Collaborator
Author
There was a problem hiding this comment.
I actually originally did that but wasn't sure if I liked it. Since it was also your first instinct, lets go with that.
I also remembered config_settings (because of bootstrap_impl tests) and thought: well, why not accept arbitrary settings?
And then the api looked like this:
pytest_test(
config_setting_variants = {
"py3.14_foo": {
"@rules_python//python/config_settings:python_version": "3.14",
"//some:flag": "foo",
}
}
)
Which, eh...
thoughts?
Collaborator
|
This actually makes me think that this could be the general API for the ruleset:
|
Incorporate review feedback by supporting the `python_versions` argument directly within the `pytest_test` macro instead of having a separate `pytest_multipy_test` macro.
…hon_versions Refactor pytest_test macro control flow to use if-else branching with a dedicated _multi_pytest_test helper instead of early returns.
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.
test(pytest): support python_versions in pytest_test macro
Testing pytest-based suites across multiple Python versions previously
required manually defining individual targets for each Python version.
Update the `pytest_test` macro in test support helpers to accept an
optional `python_versions` list. When specified, version-specific
`pytest_test` targets with formatted names are generated and grouped
under a root `test_suite`.