Skip to content
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

Allow passing deps in py_pytest_main #163

Merged
merged 1 commit into from
Jul 31, 2023
Merged
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
Empty file modified docs/py_binary.md
100755 → 100644
Empty file.
Empty file modified docs/py_library.md
100755 → 100644
Empty file.
3 changes: 2 additions & 1 deletion docs/rules.md

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

6 changes: 4 additions & 2 deletions examples/pytest/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
load("@rules_python//python:defs.bzl", "py_test")
load("@//py:defs.bzl", "py_pytest_main")

py_pytest_main(name = "__test__")
py_pytest_main(
name = "__test__",
deps = ["@pypi_pytest//:pkg"],
)

py_test(
name = "pytest_test",
Expand All @@ -13,6 +16,5 @@ py_test(
main = ":__test__.py",
deps = [
":__test__",
"@pypi_pytest//:pkg",
],
)
9 changes: 6 additions & 3 deletions examples/pytest/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@ same way the `pytest` command-line does.

## How to use

After importing this repository into your `WORKSPACE`, add to your Bazel packages containing
`_test.py` files the following:
After importing this repository into your `WORKSPACE`, add the following to your Bazel packages
which contain `_test.py` files:

```python
load("@aspect_rules_py//py:defs.bzl", "py_pytest_main")

py_pytest_main(name = "__test__")
py_pytest_main(
name = "__test__",
deps = ["@pypi_pytest//:pkg"], # change this to the pytest target in your repo.
)
```

When using this repository together with the Gazelle extension for Python from rules_python, Gazelle
Expand Down
4 changes: 3 additions & 1 deletion py/private/py_pytest_main.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,13 @@ _py_pytest_main = rule(
},
)

def py_pytest_main(name, py_library = default_py_library, **kwargs):
def py_pytest_main(name, py_library = default_py_library, deps = [], **kwargs):
"""py_pytest_main wraps the template rendering target and the final py_library.
Args:
name: The name of the runable target that updates the test entry file.
py_library: Use this attribute to override the default py_library rule.
deps: A list containing the pytest library target, e.g., @pypi_pytest//:pkg.
**kwargs: The extra arguments passed to the template rendering target.
"""

Expand All @@ -79,4 +80,5 @@ def py_pytest_main(name, py_library = default_py_library, **kwargs):
srcs = [test_main],
tags = tags,
visibility = visibility,
deps = deps,
)