-
Notifications
You must be signed in to change notification settings - Fork 6
PyTest
A fixture name, which is the identifier pytest uses to inject a fixture (a reusable test dependency) into tests, defaults to the Python function name. It can be overridden with @pytest.fixture(name="...").
Fixture scope, which determines how long a fixture instance lives and how often it is reused, defaults to function. It can be changed to session, package, module, or class.
Autouse fixtures, which are fixtures that run automatically for every test without being requested by name, default to autouse=False. They can be enabled with autouse=True.
Fixture parameters, which allow a fixture to run multiple times with different values, default to params=None. They can be set with params=[...].
Fixture parameter IDs, which are the human‑readable labels pytest assigns to parametrized test cases, default to the string representation of each parameter. They can be overridden with ids=[...] or ids=callable.
Fixture teardown, which is the cleanup logic executed after a fixture’s scope ends, is not present by default. It appears only when using yield or request.addfinalizer.
Fixture execution frequency, which determines how often a fixture is created, defaults to once per test for the function scope.
Fixture ordering, which is the sequence in which fixtures are set up, is determined by the dependency graph. Independent fixtures have no guaranteed order.
Fixture lookup, which is pytest’s process for resolving a fixture name to a fixture definition, follows this order: test function → test module → parent conftest.py files → builtin fixtures → plugin fixtures.
Missing fixture handling, which is how pytest responds when a fixture name cannot be resolved, raises a FixtureLookupError. This can be avoided by skipping or xfail inside a fixture.
Builtin fixtures, which are fixtures provided automatically by pytest, include tmp_path, tmp_path_factory, monkeypatch, capsys, capfd, caplog, recwarn, pytestconfig, and request.
Fixture injection, which is pytest’s name‑based dependency injection system, defaults to matching fixture names to test function parameters. It can be overridden with aliasing or request.getfixturevalue.
Fixture teardown timing, which determines when cleanup occurs, defaults to running at the end of the fixture’s scope.
Test discovery, which is pytest’s mechanism for locating tests, defaults to files named test_*.py or *_test.py, classes named Test*, and functions named test_*.
The test collection root, which is the directory pytest treats as the project root, is auto‑detected based on the first parent containing a config file or VCS directory.
Collection error handling, which determines how pytest reacts to errors during test discovery, defaults to failing the session.
Assertion rewriting, which is pytest’s enhancement of Python assert statements to provide detailed introspection, is enabled by default.
Assertion introspection, which is pytest’s detailed explanation of assertion failures, is enabled by default.
Test execution order, which is the sequence in which tests run, defaults to file order.
Test failure handling, which determines how pytest proceeds after a failure, defaults to continuing the session.
Traceback formatting, which controls how error stack traces are displayed, defaults to auto.
Warning handling, which determines how pytest processes Python warnings, defaults to treating PytestUnhandledCoroutineWarning and PytestReturnNotNoneWarning as errors.
Output capturing, which intercepts stdout and stderr during tests, is enabled by default.
Logging capture, which intercepts Python logging output, is enabled only for failures by default.
Skipping, which marks tests as intentionally not run, occurs only when tests are explicitly marked.
Xfail, which marks tests as expected to fail, defaults to non‑strict mode.
Marker handling, which governs how pytest interprets test markers, defaults to accepting all markers without validation.
Plugin autoloading, which automatically loads installed pytest plugins, is enabled by default.
Environment variable handling, which determines how pytest interacts with environment variables, defaults to leaving them unchanged except for internal use.
Temporary directory creation, which provides per‑test and per‑session temp paths, defaults to using tmp_path and tmp_path_factory.
Test reporting, which summarizes test outcomes, defaults to printing failures, errors, and skips.
Exit codes, which communicate session results, default to: 0 success, 1 failures, 2 usage errors, 3 internal errors, 4 no tests collected.
Parametrization, which generates multiple test cases from one test function, defaults to using repr‑based IDs.
Hook execution, which allows plugins and conftests to extend pytest, defaults to no‑op implementations.
Test selection, which determines which tests run, defaults to running all discovered tests.
Import mode, which controls how pytest imports test modules, defaults to importlib.
Path resolution, which determines how pytest modifies sys.path, defaults to adding the project root.
Test retries, which rerun failing tests, are not enabled by default.
Parallel execution, which runs tests concurrently, is not enabled by default.
Doctest execution, which runs examples embedded in documentation, is disabled by default.
Keyboard interrupt handling, which determines how pytest responds to Ctrl‑C, defaults to stopping the session.
Internal caching, which stores run metadata, defaults to writing to .pytest_cache.
Duration reporting, which identifies slow tests, is disabled by default.
Fail‑fast, which stops the session after the first failure, is disabled by default.
Keyword filtering, which selects tests by substring match, is disabled by default.
Marker filtering, which selects tests by marker expression, is disabled by default.
Test reruns, which repeat failing tests, are not enabled by default.
Session start, which initializes pytest’s runtime environment, defaults to loading plugins, discovering tests, and beginning execution.
Session finish, which finalizes pytest’s runtime environment, defaults to running teardown hooks, fixture teardowns, and printing a summary.
The addopts setting, which adds default command‑line options, defaults to an empty string.
Ignored directories, which pytest excludes from test discovery, default to .*, build, dist, CVS, _darcs, {arch}, *.egg, venv, .venv.
Console output style, which controls how test results are displayed, defaults to classic.
The cache directory, which stores internal pytest metadata, defaults to .pytest_cache.
The logging level, which controls the minimum severity of captured logs, defaults to WARNING.
The log format, which controls how log messages are formatted, defaults to '%(levelname)s:%(name)s:%(message)s'.
The log date format, which controls timestamp formatting in logs, defaults to '%Y-%m-%d %H:%M:%S'.
CLI logging, which emits log output directly to the terminal during test execution, is disabled by default.
The CLI log level, which controls the minimum severity of logs shown in the terminal, defaults to WARNING.
The CLI log format, which formats log messages printed to the terminal, defaults to '%(levelname)s:%(name)s:%(message)s'.
The CLI log date format, which timestamps CLI log messages, defaults to '%Y-%m-%d %H:%M:%S'.
The file log level, which controls the minimum severity of logs written to a file, defaults to WARNING.
The file log format, which formats log messages written to a file, defaults to '%(levelname)s:%(name)s:%(message)s'.
The file log date format, which timestamps file log messages, defaults to '%Y-%m-%d %H:%M:%S'.
Test file patterns, which determine which files pytest treats as test modules, default to test_*.py and *_test.py.
Test class patterns, which determine which classes pytest treats as test containers, default to Test*.
Test function patterns, which determine which functions pytest treats as tests, default to test_*.
Test ID escaping, which controls how pytest escapes characters in test identifiers, defaults to being enabled.
Warning filters, which determine how pytest handles warnings, default to treating two pytest‑specific warnings as errors.
Strict xfail, which treats unexpected passes as failures, is disabled by default.
The assertion pass hook, which allows plugins to react to passing assertions, is disabled by default.
Doctest option flags, which configure doctest behavior, default to 0.
Doctest encoding, which determines how doctest files are read, defaults to utf-8.
Doctest file patterns, which determine which files pytest treats as doctest sources, default to *.txt.
Doctest import‑error handling, which determines whether import errors inside doctests are ignored, defaults to not ignoring them.
Doctest failure continuation, which determines whether doctest execution continues after a failure, defaults to stopping.
Traceback style, which controls how stack traces are formatted, defaults to auto.
Duration reporting, which identifies slow tests, defaults to being disabled.
The minimum duration threshold, which filters which tests count as slow, defaults to 0.005 seconds.
Showing locals, which includes local variables in tracebacks, is disabled by default.
Verbosity, which controls the amount of output pytest prints, defaults to 0.
Random order buckets, which group tests for randomization, default to module.
The JUnit suite name, which labels the test suite in JUnit XML output, defaults to pytest.
JUnit logging, which includes log output in JUnit XML, defaults to no.
Logging passing tests in JUnit, which includes successful tests in JUnit XML logs, is disabled by default.
JUnit duration reporting, which controls how test durations appear in JUnit XML, defaults to total.
The JUnit family setting, which determines the XML schema version, defaults to xunit2.
Branch coverage, which measures branch execution in coverage reports, is disabled by default.
The coverage fail‑under threshold, which enforces minimum coverage, defaults to 0.
Coverage reporting, which determines output formats, defaults to term.
Skipping covered files, which hides fully covered files in coverage reports, is disabled by default.
Skipping empty files, which hides files with no executable code, is disabled by default.
The faulthandler timeout, which triggers stack dumps on hangs, defaults to 0.
Strict config mode, which enforces validation of config keys, is disabled by default.
Strict markers, which require markers to be declared, are disabled by default.