//python:pytest_test.bzl

A public entrypoint for pytest_test rule.

Use this to create test targets using pytest instead of having to declare the main entrypoint for your py_test rules.

In order to use this rule you’ll have to have the following packages:

  • pytest and pytest-bazel - used to invoke pytest.

  • pytest-randomly - used to have consistent random number usage.

  • pytest-shard - optional, used only if tests need to be sharded.

Added in version 2.5.0.

pytest_test(name, srcs, pytest=None, pytest_bazel=None, pytest_shard=None, pytest_randomly=None, python_versions=None, **kwargs)

Run pytest tests.

Added in version 2.5.0.

Args:
  • name – A unique name for this target.

  • srcs – List of source files (test files). These are the files that pytest will run as tests.

  • pytest – (default None)

    The pytest target to use. Defaults to @pypi//pytest.

  • pytest_bazel – (default None)

    The pytest-bazel target to use. Defaults to @pypi//pytest_bazel.

  • pytest_shard – (default None)

    The pytest-shard target to use. Defaults to @pypi//pytest_shard.

  • pytest_randomly – (default None)

    The pytest-randomly target to use. Defaults to @pypi//pytest_randomly. Pass @rules_python//python:none or another empty py_library target to disable it.

  • python_versions – (default None)

    List of Python versions to test against. If specified, a test is created for each version and grouped under a test_suite named name.

  • kwargs – Additional arguments passed to py_test. Note that main is not a supported argument.