Skip to content

feat(py_test): Allows passing tags to generated py_pytest_main. #580

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion docs/py_test.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions py/defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -146,6 +146,7 @@ def py_test(name, srcs = [], main = None, pytest_main = False, **kwargs):
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`.
"""

Expand All @@ -164,7 +165,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)

Expand All @@ -175,5 +176,6 @@ def py_test(name, srcs = [], main = None, pytest_main = False, **kwargs):
deps = deps,
main = main,
resolutions = resolutions,
tags = tags,
**kwargs
)