From e9129008a8637af5550d4eadc3a62eea750d69fe Mon Sep 17 00:00:00 2001 From: Elan Hourticolon-Retzler Date: Thu, 5 Jun 2025 22:37:55 -0700 Subject: [PATCH 1/2] Allows passing parameter to generated . --- docs/py_test.md | 3 ++- py/defs.bzl | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/docs/py_test.md b/docs/py_test.md index ea1294df..802a8540 100644 --- a/docs/py_test.md +++ b/docs/py_test.md @@ -95,7 +95,7 @@ py_pytest_main wraps the template rendering target and the final py_library. ## py_test
-py_test(name, srcs, main, pytest_main, kwargs)
+py_test(name, srcs, main, pytest_main, tags, kwargs)
 
Identical to [py_binary](./py_binary.md), but produces a target that can be used with `bazel test`. @@ -109,6 +109,7 @@ Identical to [py_binary](./py_binary.md), but produces a target that can be used | srcs | Python source files. | [] | | main | Entry point. Like rules_python, this is treated as a suffix of a file that should appear among the srcs. If absent, then [name].py is tried. As a final fallback, if the srcs has a single file, that is used as the main. | None | | pytest_main | If set, generate a [py_pytest_main](#py_pytest_main) script and use it as the main. The deps should include the pytest package (as well as the coverage package if desired). | False | +| tags | Tags to passed to generated rules (e.g. [py_pytest_main](#py_pytest_main)) | [] | | kwargs | additional named parameters to py_binary_rule. | none | diff --git a/py/defs.bzl b/py/defs.bzl index b23ded39..3456514b 100644 --- a/py/defs.bzl +++ b/py/defs.bzl @@ -134,7 +134,7 @@ def py_binary(name, srcs = [], main = None, **kwargs): **kwargs ) -def py_test(name, srcs = [], main = None, pytest_main = False, **kwargs): +def py_test(name, srcs = [], main = None, pytest_main = False, tags = [], **kwargs): """Identical to [py_binary](./py_binary.md), but produces a target that can be used with `bazel test`. Args: @@ -164,7 +164,7 @@ def py_test(name, srcs = [], main = None, pytest_main = False, **kwargs): fail("When pytest_main is set, the main attribute should not be set.") pytest_main_target = name + ".pytest_main" main = pytest_main_target + ".py" - py_pytest_main(name = pytest_main_target) + py_pytest_main(name = pytest_main_target, tags=tags) srcs.append(main) deps.append(pytest_main_target) @@ -175,5 +175,6 @@ def py_test(name, srcs = [], main = None, pytest_main = False, **kwargs): deps = deps, main = main, resolutions = resolutions, + tags = tags, **kwargs ) From d8f6d651699ee84c96e1cd0752543aba6cd44a61 Mon Sep 17 00:00:00 2001 From: Elan Hourticolon-Retzler Date: Fri, 6 Jun 2025 07:59:00 -0700 Subject: [PATCH 2/2] docs: Fixes outdated doc-string for . --- docs/py_test.md | 2 +- py/defs.bzl | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/py_test.md b/docs/py_test.md index 802a8540..b9c8a34e 100644 --- a/docs/py_test.md +++ b/docs/py_test.md @@ -109,7 +109,7 @@ Identical to [py_binary](./py_binary.md), but produces a target that can be used | srcs | Python source files. | [] | | main | Entry point. Like rules_python, this is treated as a suffix of a file that should appear among the srcs. If absent, then [name].py is tried. As a final fallback, if the srcs has a single file, that is used as the main. | None | | pytest_main | If set, generate a [py_pytest_main](#py_pytest_main) script and use it as the main. The deps should include the pytest package (as well as the coverage package if desired). | False | -| tags | Tags to passed to generated rules (e.g. [py_pytest_main](#py_pytest_main)) | [] | +| tags | If set, tags to be passed to generated targets (e.g. [py_pytest_main](#py_pytest_main)). | [] | | kwargs | additional named parameters to py_binary_rule. | none | diff --git a/py/defs.bzl b/py/defs.bzl index 3456514b..49689784 100644 --- a/py/defs.bzl +++ b/py/defs.bzl @@ -146,6 +146,7 @@ def py_test(name, srcs = [], main = None, pytest_main = False, tags = [], **kwar that is used as the main. pytest_main: If set, generate a [py_pytest_main](#py_pytest_main) script and use it as the main. The deps should include the pytest package (as well as the coverage package if desired). + tags: If set, tags to be passed to generated targets (e.g. [py_pytest_main](#py_pytest_main)). **kwargs: additional named parameters to `py_binary_rule`. """