Skip to content

Commit

Permalink
Allow passing deps in py_pytest_main (#163)
Browse files Browse the repository at this point in the history
  • Loading branch information
linzhp authored Jul 31, 2023
1 parent 57ade45 commit 88ebe87
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 7 deletions.
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,
)

0 comments on commit 88ebe87

Please sign in to comment.