The pytest Python test framework (https://docs.pytest.org/).

Backend: pants.backend.python
Config section: [pytest]

Basic options


--pytest-args="[<shell_str>, <shell_str>, ...]", ... -- [<shell_str> [<shell_str> [...]]]


default: []

Arguments to pass directly to Pytest, e.g. --pytest-args='-k test_foo --quiet'.




default: False

If true, Pants will use pytest-xdist (https://pytest-xdist.readthedocs.io/en/latest/) to parallelize tests within each python_test target.

NOTE: Enabling pytest-xdist can cause high-level scoped fixtures (for example session) to execute more than once. See the pytest-xdist docs for more info: https://pypi.org/project/pytest-xdist/#making-session-scoped-fixtures-execute-only-once




default: False

If true, don't use Pytest when running pants test.

Advanced options




default: None

If specified, install the tool using the lockfile for this named resolve.

This resolve must be defined in [python].resolves, as described in Third-party dependencies.

The resolve's entire lockfile will be installed, unless specific requirements are listed via the requirements option, in which case only those requirements will be installed. This is useful if you don't want to invalidate the tool's outputs when the resolve incurs changes to unrelated requirements.

If unspecified, and the lockfile option is unset, the tool will be installed using the default lockfile shipped with Pants.

If unspecified, and the lockfile option is set, the tool will use the custom pytest "tool lockfile" generated from the version and extra_requirements options. But note that this mechanism is deprecated.


--pytest-requirements="['<str>', '<str>', ...]"


default: []

If install_from_resolve is specified, install these requirements, at the versions provided by the specified resolve's lockfile.

Values can be pip-style requirements (e.g., tool or tool==1.2.3 or tool>=1.2.3), or addresses of python_requirement targets (or targets that generate or depend on python_requirement targets).

The lockfile will be validated against the requirements - if a lockfile doesn't provide the requirement (at a suitable version, if the requirement specifies version constraints) Pants will error.

If unspecified, install the entire lockfile.




default: pytest

The console script for the tool. Using this option is generally preferable to (and mutually exclusive with) specifying an --entry-point since console script names have a higher expectation of staying stable across releases of the tool. Usually, you will not want to change this from the default.




default: None

The entry point for the tool. Generally you only want to use this option if the tool does not offer a --console-script (which this option is mutually exclusive with). Usually, you will not want to change this from the default.




default: xunit2

The format of generated junit XML files. See https://docs.pytest.org/en/latest/reference.html#confval-junit_family.




default: None

If a non-empty string, the process execution slot id (an integer) will be exposed to tests under this environment variable name.




default: None

Path to a config file understood by Pytest (https://docs.pytest.org/en/latest/reference/customize.html#configuration-file-formats). Setting this option will disable [pytest].config_discovery. Use this option if the config is located in a non-standard location.




default: True

If true, Pants will include all relevant Pytest config files (e.g. pytest.ini) during runs. See https://docs.pytest.org/en/stable/customize.html#finding-the-rootdir for where config files should be located for Pytest to discover them.

Use [pytest].config instead if your config is in a non-standard location.

Deprecated options




default: pytest==7.0.1

Deprecated, is scheduled to be removed in version: 2.18.0.dev1.
Custom tool versions are now installed from named resolves, as described at [Lockfiles](doc:python-lockfiles).

Requirement string for the tool.


--pytest-extra-requirements="['<str>', '<str>', ...]"



Deprecated, is scheduled to be removed in version: 2.18.0.dev1.
Custom tool versions are now installed from named resolves, as described at [Lockfiles](doc:python-lockfiles).

Any additional requirement strings to use with the tool. This is useful if the tool allows you to install plugins or if you need to constrain a dependency to a certain version.




default: <default>

Deprecated, is scheduled to be removed in version: 2.18.0.dev0.
Custom tool versions are now installed from named resolves, as described at [Lockfiles](doc:python-lockfiles).

  1. If you have an existing resolve that includes the requirements for this tool,
    you can set `[pytest].install_from_resolve = "<resolve name>".
    This may be the case if the tool also provides a runtime library, and you want
    to specify the version in just one place.
  2. If not, you can set up a new resolve as described at the link above.

Either way, the resolve you choose should provide the requirements currently set by the version and extra-requirements options for this tool, which you can see by running pants help-advanced pytest.

Path to a lockfile used for installing the tool.

Set to the string <default> to use a lockfile provided by Pants, so long as you have not changed the --version and --extra-requirements options, and the tool's interpreter constraints are compatible with the default. Pants will error or warn if the lockfile is not compatible (controlled by [python].invalid_lockfile_behavior). See https://github.com/pantsbuild/pants/blob/release_2.17.0rc4/src/python/pants/backend/python/subsystems/pytest.lock for the default lockfile contents.

To use a custom lockfile, set this option to a file path relative to the build root, then run pants generate-lockfiles --resolve=pytest.

Alternatively, you can set this option to the path to a custom lockfile using pip's requirements.txt-style, ideally with --hash. Set [python].invalid_lockfile_behavior = 'ignore' so that Pants does not complain about missing lockfile headers.




default: True

Deprecated, is scheduled to be removed in version: 2.18.0.dev0.
Use the export goal's --resolve option to select tools to export, instead of using this option to exempt a tool from export-by-default.

If true, export a virtual environment with Pytest when running pants export.

This can be useful, for example, with IDE integrations to point your editor to the tool's binary.