Skip to content

test(pytest): support python_versions in pytest_test macro - #4064

Merged
rickeylev merged 5 commits into
bazel-contrib:mainfrom
rickeylev:add_pytest_multiversion_support
Aug 17, 2026
Merged

test(pytest): support python_versions in pytest_test macro#4064
rickeylev merged 5 commits into
bazel-contrib:mainfrom
rickeylev:add_pytest_multiversion_support

Conversation

@rickeylev

@rickeylev rickeylev commented Aug 16, 2026

Copy link
Copy Markdown
Collaborator

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`.

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
rickeylev requested review from aignas and removed request for aignas August 16, 2026 23:24
@rickeylev
rickeylev marked this pull request as ready for review August 16, 2026 23:39
@rickeylev
rickeylev requested a review from aignas as a code owner August 16, 2026 23:39
Comment on lines +36 to +39
python_versions = [
"3.14",
"3.13",
],

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

@aignas

aignas commented Aug 17, 2026

Copy link
Copy Markdown
Collaborator

This actually makes me think that this could be the general API for the ruleset:

  • py_library - python_versions adds target_compatible_with flags. to mark compatibility.
  • py_test - python_versions tests for all versions.
  • py_binary - no need to pass python_versions?

Incorporate review feedback by supporting the `python_versions` argument
directly within the `pytest_test` macro instead of having a separate
`pytest_multipy_test` macro.
@rickeylev rickeylev changed the title test(pytest): add pytest_multipy_test macro for multi-version testing test(pytest): support python_versions in pytest_test macro Aug 17, 2026
…hon_versions

Refactor pytest_test macro control flow to use if-else branching with a
dedicated _multi_pytest_test helper instead of early returns.
@rickeylev
rickeylev added this pull request to the merge queue Aug 17, 2026
Merged via the queue into bazel-contrib:main with commit 1b525fa Aug 17, 2026
5 checks passed
@rickeylev
rickeylev deleted the add_pytest_multiversion_support branch August 17, 2026 06:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants