Use pytest to run tests, using a wrapper script to interface with Bazel.
Example:
load("@caseyduquettesc_rules_python_pytest//python_pytest:defs.bzl", "py_pytest_test")
py_pytest_test(
name = "test_w_pytest",
size = "small",
srcs = ["test.py"],
)By default, @pip//pytest is added to deps.
If sharding is used (when shard_count > 1) then @pip//pytest_shard is also added.
To instead provide explicit deps for the pytest library, set pytest_deps:
py_pytest_test(
name = "test_w_my_pytest",
shard_count = 2,
srcs = ["test.py"],
pytest_deps = [requirement("pytest"), requirement("pytest-shard"), ...],
)py_pytest_test(name, srcs, deps, args, pytest_deps, pip_repo, kwargs)
Wrapper macro for `py_test` which supports pytest.
PARAMETERS
| Name | Description | Default Value |
|---|---|---|
| name | A unique name for this target. | none |
| srcs | Python source files. | none |
| deps | Dependencies, typically py_library. |
[] |
| args | Additional command-line arguments to pytest. See https://docs.pytest.org/en/latest/how-to/usage.html | [] |
| pytest_deps | Labels of the pytest tool and other packages it may import. | None |
| pip_repo | Name of the external repository where Python packages are installed. It's typically created by pip.parse. This attribute is used only when pytest_deps is unset. |
"pip" |
| kwargs | Additional named parameters to py_test. | none |