Type LegacyConfig | Config
Schema URL https://catalog.lintel.tools/schemas/schemastore/pyproject/_shared/latest--partial-pytest.json
Parent schema pyproject

JSON schema for pytest configuration options under [tool.pytest] in pyproject.toml.

One of

1. LegacyConfig object
2. Config

Definitions

LegacyConfig object

Legacy configuration using ini_options table (pytest <9)

ini_options required

The ini_options table is used as a bridge between the existing pytest.ini configuration system and future configuration formats. pytest.ini takes precedence over [tool.pytest.ini_options] in pyproject.toml.

All of: IniOptionsPytest object, IniOptionsAsyncio object
IniOptionsPytest object
addopts string[] | string

Add the specified OPTS to the set of command line arguments as if they had been specified by the user.

cache_dir string

Sets the directory where the cache plugin's content is stored.

Default: ".pytest_cache"
collect_imported_tests string | boolean

Settings this to false will make pytest collect classes/functions from test files only if they are defined in that file (as opposed to imported there).

Default: "true"
consider_namespace_packages string | boolean

Controls if pytest should attempt to identify namespace packages when collecting Python modules.

Default: "false"
console_output_style string

Sets console output style during test execution.

Default: "progress"
Values: "classic" "progress" "progress-even-when-capture-no" "count" "times"
disable_test_id_escaping_and_forfeit_all_rights_to_community_support string | boolean

pytest by default escapes any non-ascii characters used in unicode strings for the parametrization because it has several downsides. If however you would like to use unicode strings in parametrization and see them in the terminal as is (non-escaped), use this option in your configuration file

Default: "false"
doctest_encoding string

Default encoding to use to decode text files with docstrings.

doctest_optionflags string[] | string

One or more doctest flag names from the standard doctest module.

empty_parameter_set_mark string

Allows to pick the action for empty parametersets in parameterization.

Default: "skip"
Values: "skip" "xfail" "fail_at_collect"
enable_assertion_pass_hook string | boolean

Enables the pytest_assertion_pass hook. Make sure to delete any previously generated .pyc cache files.

Default: "false"
faulthandler_exit_on_timeout string | boolean

Exit the pytest process after the per-test timeout is reached by passing exit=True to the faulthandler.dump_traceback_later() function. This is particularly useful to avoid wasting CI resources for test suites that are prone to putting the main Python interpreter into a deadlock state.

Default: "false"
faulthandler_timeout string | integer

Dumps the tracebacks of all threads if a test takes longer than X seconds to run (including fixture setup and teardown). Implemented using the faulthandler.dump_traceback_later() function, so all caveats there apply.

filterwarnings string[] | string

Sets a list of filters and actions that should be taken for matched warnings. By default all warnings emitted during the test session will be displayed in a summary at the end of the test session.

junit_duration_report string

Configures how durations are recorded into the JUnit XML report:

Default: "total"
Values: "total" "call"
junit_family string

Configures the format of the generated JUnit XML file.

Default: "xunit2"
Values: "legacy" "xunit1" "xunit2"
junit_log_passing_tests string | boolean

If junit_logging is enabled, configures if the captured output should be written to the JUnit XML file for passing tests.

Default: "true"
junit_logging string

Configures if captured output should be written to the JUnit XML file.

Default: "no"
Values: "no" "log" "system-out" "system-err" "out-err" "all"
junit_suite_name string

To set the name of the root test suite xml item, you can configure the junit_suite_name option in your config file.

log_auto_indent string | string | integer

Allow selective auto-indentation of multiline log messages.

log_cli string | boolean

Enable log display during test run (also known as "live logging").

Default: "false"
log_cli_date_format string

Sets a time.strftime()-compatible string that will be used when formatting dates for live logging.

log_cli_format string

Sets a logging-compatible string used to format live logging messages.

log_cli_level integer | string | string

A minimum log level. Can be level name or integer value.

log_date_format string

Sets a time.strftime()-compatible string that will be used when formatting dates for logging capture.

log_file string

Sets a file name relative to the current working directory where log messages should be written to, in addition to the other logging facilities that are active.

log_file_date_format string

Sets a time.strftime()-compatible string that will be used when formatting dates for the logging file.

log_file_format string

Sets a logging-compatible string used to format logging messages redirected to the logging file.

log_file_level integer | string | string

A minimum log level. Can be level name or integer value.

log_file_mode string

Sets the mode that the logging file is opened with. The options are 'w' to recreate the file (the default) or 'a' to append to the file.

Default: "a"
Values: "a" "w"
log_format string

Sets a logging-compatible string used to format captured logging messages.

log_level integer | string | string

A minimum log level. Can be level name or integer value.

markers string[] | string

When the strict_markers configuration option is set, only known markers - defined in code by core pytest or some plugin - are allowed. You can list additional markers in this setting to add them to the whitelist, in which case you probably want to set strict_markers to true to avoid future regressions.

minversion string

Specifies a minimal pytest version required for running tests.

norecursedirs string[] | string

Set the directory basename patterns to avoid when recursing for test discovery. The individual (fnmatch-style) patterns are applied to the basename of a directory to decide if to recurse into it.

Default: "*.egg .* _darcs build CVS dist node_modules venv {arch}"
python_classes string[] | string

One or more name prefixes or glob-style patterns determining which classes are considered for test collection. Search for multiple glob patterns by adding a space between patterns. By default, pytest will consider any class prefixed with Test as a test collection.

python_files string[] | string

One or more Glob-style file patterns determining which python files are considered as test modules.

Default:
[
  "test_*.py",
  "*_test.py"
]
python_functions string[] | string

One or more name prefixes or glob-patterns determining which test functions and methods are considered tests. Search for multiple glob patterns by adding a space between patterns. By default, pytest will consider any function prefixed with test as a test.

Default:
[
  "test_*"
]
pythonpath string[] | string

Sets list of directories that should be added to the python search path. Directories will be added to the head of sys.path. Similar to the PYTHONPATH environment variable, the directories will be included in where Python will look for imported modules. Paths are relative to the rootdir directory.

required_plugins string[] | string

A list of plugins that must be present for pytest to run. Plugins can be listed with or without version specifiers directly following their name.

strict string | boolean

If set to true, enable 'strict mode', which enables a number of other strict options.

Default: "false"
strict_config string | boolean

If set to true, any warnings encountered while parsing the pytest section of the configuration file will raise errors.

Default: "false"
strict_markers string | boolean

If set to true, markers not registered in the markers section of the configuration file will raise errors.

Default: "false"
strict_parametrization_ids string | boolean

If set to true, pytest emits an error if it detects non-unique parameter set IDs. If not set (the default), pytest automatically handles this by adding 0, 1, … to duplicate IDs, making them unique.

Default: "false"
strict_xfail string | boolean

If set to true, tests marked with @pytest.mark.xfail that actually succeed will by default fail the test suite.

Default: "false"
testpaths string[] | string

Sets list of directories that should be searched for tests when no specific directories, files or test ids are given in the command line when executing pytest from the rootdir directory. File system paths may use shell-style wildcards, including the recursive ** pattern. Useful when all project tests are in a known location to speed up test collection and to avoid picking up undesired tests by accident.

tmp_path_retention_count string | integer

How many sessions should we keep the tmp_path directories, according to tmp_path_retention_policy.

Default: "3"
tmp_path_retention_policy string

Controls which directories created by the tmp_path fixture are kept around, based on test outcome.

Default: "all"
Values: "all" "failed" "none"
truncation_limit_chars string | integer

Controls maximum number of characters to truncate assertion message contents. Setting value to 0 disables the character limit for truncation.

Default: "640"
truncation_limit_lines string | integer

Controls maximum number of linesto truncate assertion message contents. Setting value to 0 disables the lines limit for truncation.

Default: "8"
usefixtures string[] | string

List of fixtures that will be applied to all test functions; this is semantically the same to apply the @pytest.mark.usefixtures marker to all test functions.

verbosity_assertions string | integer | string

Set a verbosity level specifically for assertion related output, overriding the application wide level.

verbosity_subtests string | integer | string

Set the verbosity level specifically for passed subtests. A value of 1 or higher will show output for passed subtests (failed subtests are always reported). Passed subtests output can be suppressed with the value 0, which overwrites the -v command-line option.

verbosity_test_cases string | integer | string

Set a verbosity level specifically for test case execution related output, overriding the application wide level.

xfail_strict string | boolean

DEPRECATED. Alias for strict_xfail. If true, test suite will fail if a test marked with @pytest.mark.xfail unexpectedly passes.

Default: "false"
IniOptionsAsyncio object
asyncio_default_fixture_loop_scope string
Values: "function" "class" "module" "package" "session"
asyncio_default_test_loop_scope string
Values: "function" "class" "module" "package" "session"
asyncio_debug string | boolean

Enables asyncio debug mode for the default event loop used by asynchronous tests and fixtures.

Default: "false"
asyncio_mode string

Sets the asyncio mode for pytest-asyncio.

Default: "strict"
One of: const: "auto" const: "auto", const: "strict" const: "strict"
AsyncioScope string
LogLevel integer | string | string

A minimum log level. Can be level name or integer value.

Config

Direct key configuration with proper TOML types (pytest >=9) https://docs.pytest.org/en/stable/reference/reference.html#configuration-options

ConfigOptionsPytest object
addopts string[]

Add the specified OPTS to the set of command line arguments as if they had been specified by the user.

cache_dir string

Sets the directory where the cache plugin’s content is stored.

Default: ".pytest_cache"
collect_imported_tests boolean

Settings this to false will make pytest collect classes/functions from test files only if they are defined in that file (as opposed to imported there).

Default: true
consider_namespace_packages boolean

Controls if pytest should attempt to identify namespace packages when collecting Python modules.

Default: false
console_output_style string

Sets console output style during test execution.

Default: "progress"
Values: "classic" "progress" "progress-even-when-capture-no" "count" "times"
disable_test_id_escaping_and_forfeit_all_rights_to_community_support boolean

pytest by default escapes any non-ascii characters used in unicode strings for the parametrization because it has several downsides. If however you would like to use unicode strings in parametrization and see them in the terminal as is (non-escaped), use this option in your configuration file

Default: false
doctest_encoding string

Default encoding to use to decode text files with docstrings.

doctest_optionflags string[]

One or more doctest flag names from the standard doctest module.

empty_parameter_set_mark string

Allows to pick the action for empty parametersets in parameterization.

Default: "skip"
Values: "skip" "xfail" "fail_at_collect"
enable_assertion_pass_hook boolean

Enables the pytest_assertion_pass hook. Make sure to delete any previously generated .pyc cache files.

Default: false
faulthandler_exit_on_timeout boolean

Exit the pytest process after the per-test timeout is reached by passing exit=True to the faulthandler.dump_traceback_later() function. This is particularly useful to avoid wasting CI resources for test suites that are prone to putting the main Python interpreter into a deadlock state.

Default: false
faulthandler_timeout integer

Dumps the tracebacks of all threads if a test takes longer than X seconds to run (including fixture setup and teardown). Implemented using the faulthandler.dump_traceback_later() function, so all caveats there apply.

filterwarnings string[]

Sets a list of filters and actions that should be taken for matched warnings. By default all warnings emitted during the test session will be displayed in a summary at the end of the test session.

junit_duration_report string

Configures how durations are recorded into the JUnit XML report:

Default: "total"
Values: "total" "call"
junit_family string

Configures the format of the generated JUnit XML file.

Default: "xunit2"
Values: "legacy" "xunit1" "xunit2"
junit_log_passing_tests boolean

If junit_logging is enabled, configures if the captured output should be written to the JUnit XML file for passing tests.

Default: true
junit_logging string

Configures if captured output should be written to the JUnit XML file.

Default: "no"
Values: "no" "log" "system-out" "system-err" "out-err" "all"
junit_suite_name string

To set the name of the root test suite xml item, you can configure the junit_suite_name option in your config file.

log_auto_indent boolean | integer | string

Allow selective auto-indentation of multiline log messages.

log_cli boolean

Enable log display during test run (also known as “live logging”).

Default: false
log_cli_date_format string

Sets a time.strftime()-compatible string that will be used when formatting dates for live logging.

log_cli_format string

Sets a logging-compatible string used to format live logging messages.

log_cli_level integer | string | string

A minimum log level. Can be level name or integer value.

log_date_format string

Sets a time.strftime()-compatible string that will be used when formatting dates for logging capture.

log_file string

Sets a file name relative to the current working directory where log messages should be written to, in addition to the other logging facilities that are active.

log_file_date_format string

Sets a time.strftime()-compatible string that will be used when formatting dates for the logging file.

log_file_format string

Sets a logging-compatible string used to format logging messages redirected to the logging file.

log_file_level integer | string | string

A minimum log level. Can be level name or integer value.

log_file_mode string

Sets the mode that the logging file is opened with. The options are 'w' to recreate the file (the default) or 'a' to append to the file.

Default: "a"
Values: "a" "w"
log_format string

Sets a logging-compatible string used to format captured logging messages.

log_level integer | string | string

A minimum log level. Can be level name or integer value.

markers string[]

When the strict_markers configuration option is set, only known markers - defined in code by core pytest or some plugin - are allowed. You can list additional markers in this setting to add them to the whitelist, in which case you probably want to set strict_markers to true to avoid future regressions.

minversion string

Specifies a minimal pytest version required for running tests.

norecursedirs string[]

Set the directory basename patterns to avoid when recursing for test discovery. The individual (fnmatch-style) patterns are applied to the basename of a directory to decide if to recurse into it.

Default:
[
  "*.egg",
  ".*",
  "_darcs",
  "build",
  "CVS",
  "dist",
  "node_modules",
  "venv",
  "{arch}"
]
python_classes string[]

One or more name prefixes or glob-style patterns determining which classes are considered for test collection. Search for multiple glob patterns by adding a space between patterns. By default, pytest will consider any class prefixed with Test as a test collection.

python_files string[]

One or more Glob-style file patterns determining which python files are considered as test modules.

Default:
[
  "test_*.py",
  "*_test.py"
]
python_functions string[]

One or more name prefixes or glob-patterns determining which test functions and methods are considered tests. Search for multiple glob patterns by adding a space between patterns. By default, pytest will consider any function prefixed with test as a test.

Default:
[
  "test_*"
]
pythonpath string[]

Sets list of directories that should be added to the python search path. Directories will be added to the head of sys.path. Similar to the PYTHONPATH environment variable, the directories will be included in where Python will look for imported modules. Paths are relative to the rootdir directory.

required_plugins string[]

A list of plugins that must be present for pytest to run. Plugins can be listed with or without version specifiers directly following their name.

strict boolean

If set to true, enable 'strict mode', which enables a number of other strict options.

Default: false
strict_config boolean

If set to true, any warnings encountered while parsing the pytest section of the configuration file will raise errors.

Default: false
strict_markers boolean

If set to true, markers not registered in the markers section of the configuration file will raise errors.

Default: false
strict_parametrization_ids boolean

If set to true, pytest emits an error if it detects non-unique parameter set IDs. If not set (the default), pytest automatically handles this by adding 0, 1, … to duplicate IDs, making them unique.

Default: false
strict_xfail boolean

If set to true, tests marked with @pytest.mark.xfail that actually succeed will by default fail the test suite.

Default: false
testpaths string[]

Sets list of directories that should be searched for tests when no specific directories, files or test ids are given in the command line when executing pytest from the rootdir directory. File system paths may use shell-style wildcards, including the recursive ** pattern. Useful when all project tests are in a known location to speed up test collection and to avoid picking up undesired tests by accident.

tmp_path_retention_count string

How many sessions should we keep the tmp_path directories, according to tmp_path_retention_policy.

Default: "3"
tmp_path_retention_policy string

Controls which directories created by the tmp_path fixture are kept around, based on test outcome.

Default: "all"
Values: "all" "failed" "none"
truncation_limit_chars integer

Controls maximum number of characters to truncate assertion message contents. Setting value to 0 disables the character limit for truncation.

Default: 640
truncation_limit_lines integer

Controls maximum number of linesto truncate assertion message contents. Setting value to 0 disables the lines limit for truncation.

Default: 8
usefixtures string[]

List of fixtures that will be applied to all test functions; this is semantically the same to apply the @pytest.mark.usefixtures marker to all test functions.

verbosity_assertions string | string

Set a verbosity level specifically for assertion related output, overriding the application wide level.

verbosity_subtests integer | string

Set the verbosity level specifically for passed subtests. A value of 1 or higher will show output for passed subtests (failed subtests are always reported). Passed subtests output can be suppressed with the value 0, which overwrites the -v command-line option.

verbosity_test_cases integer | string

Set a verbosity level specifically for test case execution related output, overriding the application wide level.

xfail_strict boolean

DEPRECATED. Alias for strict_xfail. If true, test suite will fail if a test marked with @pytest.mark.xfail unexpectedly passes.

Default: false
ConfigOptionsAsyncio object
asyncio_default_fixture_loop_scope string
Values: "function" "class" "module" "package" "session"
asyncio_default_test_loop_scope string
Values: "function" "class" "module" "package" "session"
asyncio_debug boolean

Enables asyncio debug mode for the default event loop used by asynchronous tests and fixtures.

Default: false
asyncio_mode string

Sets the asyncio mode for pytest-asyncio.

Default: "strict"
One of: const: "auto" const: "auto", const: "strict" const: "strict"