Skip to content

Commit 5fd7d8f

Browse files
authored
tests: implement pytest_test rule for internal test usage (#3931)
This implements a pytest_test rule based upon the pytest_bazel library. The core implementation of this is fairly simple: a file is generated that calls `pytest.main()` with the `srcs` to test. This generated file is the file that is run by `py_test`. For now, this is kept under tests/support soas to use it for our own tests while some design decisions are figured out. Work towards #3594
1 parent d92af74 commit 5fd7d8f

13 files changed

Lines changed: 394 additions & 141 deletions

File tree

.bazelversion

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
9.x
1+
9.1.1

AGENTS.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,6 @@ The `repository_ctx` API docs are at: https://bazel.build/rules/lib/builtins/rep
121121
e.g. given `load("//foo:bar.bzl", ...)`, the target is `//foo:bar_bzl`.
122122
* For files outside rules_python: remove the `.bzl` suffix. e.g. given
123123
`load("@foo//foo:bar.bzl", ...)`, the target is `@foo//foo:bar`.
124-
* `bzl_library()` targets should be kept in alphabetical order by name.
125124

126125
Example:
127126

BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
3838
# Exclude directories that are separate packages/workspaces or only for testing/examples
3939
# gazelle:exclude tests
4040
# gazelle:exclude examples
41+
# gazelle:exclude gazelle
4142

4243
# Exclude internal development tools and dependencies that users don't need
4344
# gazelle:exclude internal_dev_setup.bzl

MODULE.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ dev_pip.parse(
214214
python_version = "3.11",
215215
requirements_lock = "//tests/multi_pypi/beta:requirements.txt",
216216
)
217-
use_repo(dev_pip, "dev_pip", "pypi_alpha", "pypi_beta", "pypiserver")
217+
use_repo(dev_pip, "dev_pip", "pypi", "pypi_alpha", "pypi_beta", "pypiserver")
218218

219219
# Bazel integration test setup below
220220

docs/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ sphinx_build_binary(
198198
target_compatible_with = _TARGET_COMPATIBLE_WITH,
199199
deps = [
200200
"@dev_pip//myst_parser",
201+
"@dev_pip//pytest",
201202
"@dev_pip//readthedocs_sphinx_ext",
202203
"@dev_pip//sphinx",
203204
"@dev_pip//sphinx_autodoc2",

docs/pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,6 @@ dependencies = [
1717
"pyelftools",
1818
"macholib",
1919
"markupsafe",
20+
"pytest",
21+
"pytest-bazel",
2022
]

docs/requirements.txt

Lines changed: 140 additions & 138 deletions
Large diffs are not rendered by default.

docs/uv.lock

Lines changed: 112 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/pytest_test/BUILD.bazel

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
load("//tests/support:support.bzl", "SUPPORTS_BZLMOD")
2+
load("//tests/support/pytest_test:pytest_test.bzl", "pytest_test")
3+
4+
pytest_test(
5+
name = "pytest_script_venv_test",
6+
srcs = [
7+
"basic_test.py",
8+
],
9+
config_settings = {
10+
"@rules_python//python/config_settings:bootstrap_impl": "script",
11+
"@rules_python//python/config_settings:venvs_site_packages": "yes",
12+
},
13+
target_compatible_with = SUPPORTS_BZLMOD,
14+
)
15+
16+
pytest_test(
17+
name = "pytest_default_test",
18+
srcs = [
19+
"basic_test.py",
20+
],
21+
target_compatible_with = SUPPORTS_BZLMOD,
22+
)

tests/pytest_test/basic_test.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
def test_foo():
2+
assert True

0 commit comments

Comments
 (0)