Repository navigation
feat(rules): expose pytest_test rule for public use #4244
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
rickeylev
merged 7 commits into
bazel-contrib:main
from
aignas:aignas.feat.expose-pytest-rule
Oct 12, 2026
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
6738400
feat(rules): expose pytest_test rule for public use
aignas ceaef46
doc: news
aignas 613df79
fix(pytest_test): address review feedback for public pytest_test rule
rickeylev b5f7467
test(pytest_test): document why select() is used in deps
rickeylev 1195fc0
fix(pytest_test): declare abstract PyPI deps via pip.dep in MODULE.bazel
rickeylev 8a3784f
agents: add rules_python usage auditor and open-question label rule
rickeylev 2bac5e5
Merge remote-tracking branch 'upstream/main' into aignas.feat.expose-…
rickeylev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,4 +21,6 @@ dependencies = [ | |
| "pytest", | ||
| "pytest-bazel", | ||
| "pytest-mock", | ||
| "pytest-randomly", | ||
| "pytest-shard", | ||
| ] | ||
Large diffs are not rendered by default.
Oops, something went wrong.
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| (rules) Added {obj}`pytest_test`, which facilitates running of pytest tests. | ||
| It supports generating multiple test targets for more than one Python version | ||
| and uses `pytest-randomly` and `pytest-shard`. | ||
| ([#3594](https://github.com/bazel-contrib/rules_python/issues/3594)) |
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| load("@bazel_skylib//:bzl_library.bzl", "bzl_library") | ||
| load("//python/private:distribution_filegroup.bzl", "distribution_filegroup") | ||
| load("//python/private:visibility.bzl", "NOT_ACTUALLY_PUBLIC") | ||
|
|
||
| package(default_visibility = ["//:__subpackages__"]) | ||
|
|
||
| filegroup( | ||
| name = "bootstrap_template", | ||
| srcs = ["pytest_bootstrap_template.py"], | ||
| visibility = NOT_ACTUALLY_PUBLIC, | ||
| ) | ||
|
|
||
| # keep | ||
| bzl_library( | ||
| name = "pytest_test", | ||
| srcs = ["pytest_test.bzl"], | ||
| deps = [ | ||
| "//python:py_test", | ||
| ], | ||
| ) | ||
|
|
||
| distribution_filegroup( | ||
| name = "distribution", | ||
| ) | ||
|
|
||
| # These aliases are used to avoid duplicate targets in the deps list | ||
| alias( | ||
| name = "default_pytest", | ||
| actual = "@pypi//pytest", | ||
| visibility = NOT_ACTUALLY_PUBLIC, | ||
| ) | ||
|
|
||
| alias( | ||
| name = "default_pytest_bazel", | ||
| actual = "@pypi//pytest_bazel", | ||
| visibility = NOT_ACTUALLY_PUBLIC, | ||
| ) | ||
|
|
||
| alias( | ||
| name = "default_pytest_shard", | ||
| actual = "@pypi//pytest_shard", | ||
| visibility = NOT_ACTUALLY_PUBLIC, | ||
| ) | ||
|
|
||
| alias( | ||
| name = "default_pytest_randomly", | ||
| actual = "@pypi//pytest_randomly", | ||
|
rickeylev marked this conversation as resolved.
|
||
| visibility = NOT_ACTUALLY_PUBLIC, | ||
| ) | ||
1 change: 1 addition & 0 deletions
1
.../pytest_test/pytest_bootstrap_template.py → .../pytest_test/pytest_bootstrap_template.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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| """ | ||
| A public entrypoint for `pytest_test` rule. | ||
|
|
||
| Use this to create test targets using [pytest](https://pypi.org/project/pytest) | ||
| instead of having to declare the main entrypoint for your {obj}`py_test` rules. | ||
|
|
||
| In order to use this rule you'll have to have the following packages: | ||
| * `pytest` and `pytest-bazel` - used to invoke pytest. | ||
| * `pytest-randomly` - used to have consistent random number usage. | ||
| * `pytest-shard` - optional, used only if tests need to be sharded. | ||
|
|
||
| :::{versionadded} VERSION_NEXT_FEATURE | ||
| ::: | ||
| """ | ||
|
|
||
| load("//python/private/pytest_test:pytest_test.bzl", _pytest_test = "pytest_test") | ||
|
|
||
| pytest_test = _pytest_test |
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.