Skip to content

Commit

Permalink
Allow passing deps in py_pytest_main
Browse files Browse the repository at this point in the history
  • Loading branch information
linzhp committed Jun 22, 2023
1 parent bb956d0 commit 56ff8e1
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
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",
],
)
5 changes: 4 additions & 1 deletion examples/pytest/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ After importing this repository into your `WORKSPACE`, add to your Bazel package
```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 56ff8e1

Please sign in to comment.