Skip to content
Paul Sweatte edited this page Jun 8, 2026 · 2 revisions

Pytest Combined Defaults FAQ (Runtime + Config, With Inline Definitions)

What is the default fixture name?

A fixture (a reusable test dependency that pytest injects into tests by name) defaults to using its Python function name. It can be overridden with @pytest.fixture(name="...").

What is the default fixture scope?

The fixture scope (the lifetime of a fixture instance, controlling how often it is created and reused) defaults to function. It can be overridden with scope="session", "package", "module", or "class".

Are fixtures autouse by default?

Autouse fixtures (fixtures that run automatically for every test without being requested by name) default to autouse=False. They can be enabled with autouse=True.

Do fixtures have parameters by default?

Fixture parameters (values that cause pytest to run the fixture multiple times with different inputs) default to params=None. They can be set with params=[...].

How are fixture parameter IDs generated by default?

Fixture parameter IDs (the human‑readable names pytest assigns to parametrized test cases) default to the string representation of each parameter. They can be overridden with ids=[...] or ids=callable.

Do fixtures have teardown logic by default?

Fixture teardown (cleanup code that runs after the fixture’s scope ends) is not present by default. It appears only when using yield or request.addfinalizer.

How often is a fixture executed by default?

A fixture instance is created once per its scope. For the default function scope, it runs once per test.

How does pytest order fixtures by default?

Fixture ordering (the sequence in which fixtures are set up) is determined by the dependency graph. Independent fixtures have no guaranteed order.

How does pytest look up fixtures by default?

Fixture lookup (the process pytest uses to find a fixture by name) follows this order: test function → test module → parent conftest.py files → builtin fixtures → plugin fixtures.

What happens if a fixture is missing?

A missing fixture triggers a FixtureLookupError (pytest’s error for unresolved fixture names). This can be avoided by skipping or xfail inside a fixture.

What builtin fixtures exist by default?

Builtin fixtures (fixtures provided automatically by pytest) include tmp_path, tmp_path_factory, monkeypatch, capsys, capfd, caplog, recwarn, pytestconfig, and request.

How are fixtures injected by default?

Fixture injection (pytest’s name‑based dependency injection system) uses the fixture name to match parameters. It can be overridden with aliasing or request.getfixturevalue.

When do fixtures tear down by default?

Fixture teardown occurs at the end of the fixture’s scope. This can be changed by altering scope or using nested fixtures.

What is the default test discovery pattern?

Test discovery (pytest’s process for finding tests) defaults to files named test_*.py or *_test.py, classes named Test*, and functions named test_*.

What is the default test collection root?

The test collection root (the directory pytest treats as the project root) is auto‑detected based on the first parent containing a config file or VCS directory.

What is the default behavior for test collection errors?

Collection errors (failures during test discovery) cause the session to error. They can be suppressed with --continue-on-collection-errors.

What is the default assertion rewriting behavior?

Assertion rewriting (pytest’s mechanism for enhancing Python assert statements with introspection) is enabled for test modules by default.

What is the default behavior for assertion introspection?

Assertion introspection (pytest’s detailed explanation of why an assertion failed) is enabled by default. It can be disabled by running Python in optimized mode.

What is the default behavior for test execution order?

Test execution order (the sequence in which tests run) defaults to file order.

What is the default behavior for test failures?

A failing test stops only that test. The session continues unless -x or --maxfail is used.

What is the default traceback style?

The traceback style (the formatting of error stack traces) defaults to auto.

What is the default behavior for warnings?

Pytest converts PytestUnhandledCoroutineWarning and PytestReturnNotNoneWarning into errors. Other warnings pass through.

What is the default behavior for capturing stdout and stderr?

Output capturing (pytest’s interception of stdout and stderr) is enabled by default. It can be disabled with -s.

What is the default behavior for logging?

Logging capture (pytest’s interception of Python logging output) is enabled only for failures. CLI logging is disabled by default.

What is the default behavior for skipping tests?

Skipping (pytest’s mechanism for marking tests as intentionally not run) occurs only when tests are marked with skip or skipif.

What is the default behavior for xfail?

Xfail (pytest’s “expected failure” marker) defaults to non‑strict. Unexpected passes are XPASS.

What is the default behavior for markers?

Markers (labels attached to tests for selection or behavior changes) are accepted without validation. They can be made strict with --strict-markers.

What is the default behavior for plugin loading?

Plugin autoloading (pytest’s automatic loading of installed plugins) is enabled by default.

What is the default behavior for environment variables?

Pytest does not modify environment variables except internally.

What is the default behavior for temporary directories?

tmp_path creates a unique directory per test. tmp_path_factory creates session‑level directories.

What is the default behavior for test reports?

Test reporting (pytest’s summary of test outcomes) prints failures, errors, and skips.

What is the default behavior for exit codes?

Exit codes follow pytest’s standard mapping: 0 success, 1 failures, 2 usage errors, 3 internal errors, 4 no tests collected.

What is the default behavior for test parametrization?

Parametrization (pytest’s mechanism for generating multiple test cases from one test function) defaults to using repr‑based IDs.

What is the default behavior for hooks?

Hooks (pytest’s plugin extension points) default to no‑op implementations.

What is the default behavior for test selection?

Test selection (choosing which tests to run) defaults to running all discovered tests.

What is the default behavior for import mode?

Import mode (how pytest imports test modules) defaults to importlib.

What is the default behavior for path resolution?

Pytest adds the project root to sys.path.

What is the default behavior for test retries?

Pytest does not retry tests by default.

What is the default behavior for parallel execution?

Pytest does not run tests in parallel by default.

What is the default behavior for doctest execution?

Doctests do not run unless explicitly enabled.

What is the default behavior for keyboard interrupts?

Pytest stops the session on the first interrupt.

What is the default behavior for internal caching?

Internal caching (pytest’s storage of run metadata) writes to .pytest_cache.

What is the default behavior for test durations?

Pytest does not report slow tests unless durations are enabled.

What is the default behavior for fail‑fast?

Fail‑fast is disabled by default.

What is the default behavior for keyword filtering?

Keyword filtering (selecting tests by substring match) is disabled by default.

What is the default behavior for marker filtering?

Marker filtering (selecting tests by marker expression) is disabled by default.

What is the default behavior for rerunning tests?

Pytest does not rerun tests by default.

What is the default behavior for session start?

Pytest loads plugins, discovers tests, and begins execution.

What is the default behavior for session finish?

Pytest runs teardown hooks, fixture teardowns, and prints a summary.


Configuration Defaults

What is the default value of addopts?

The default is an empty string.

What directories does pytest ignore by default?

.*, build, dist, CVS, _darcs, {arch}, *.egg, venv, .venv

What is the default console output style?

classic

Where does pytest store its cache by default?

.pytest_cache

What is the default logging level?

WARNING

What is the default log format?

'%(levelname)s:%(name)s:%(message)s'

What is the default log date format?

'%Y-%m-%d %H:%M:%S'

Is CLI logging enabled by default?

No.

What is the default CLI log level?

WARNING

What is the default CLI log format?

'%(levelname)s:%(name)s:%(message)s'

What is the default CLI log date format?

'%Y-%m-%d %H:%M:%S'

What is the default file log level?

WARNING

What is the default file log format?

'%(levelname)s:%(name)s:%(message)s'

What is the default file log date format?

'%Y-%m-%d %H:%M:%S'

What test file patterns does pytest use by default?

test_*.py and *_test.py

What class name pattern does pytest use by default?

Test*

What function name pattern does pytest use by default?

test_*

Is test ID escaping disabled by default?

No.

What warnings does pytest filter by default?

It errors on PytestUnhandledCoroutineWarning and PytestReturnNotNoneWarning.

Is xfail strict by default?

No.

Is the assertion pass hook enabled by default?

No.

What are the default doctest option flags?

0

What is the default doctest encoding?

utf-8

What doctest file pattern is used by default?

*.txt

Does pytest ignore doctest import errors by default?

No.

Does pytest continue doctest execution on failure by default?

No.

What traceback style does pytest use by default?

auto

How many slow tests does pytest report by default?

None.

What is the default minimum duration threshold?

0.005 seconds.

Does pytest show locals in tracebacks by default?

No.

What is the default verbosity?

0

What is the default random order bucket?

module

What is the default JUnit suite name?

pytest

What is the default JUnit logging mode?

no

Does pytest log passing tests to JUnit by default?

No.

What JUnit duration report mode is used by default?

total

What JUnit family is used by default?

xunit2

Does coverage measure branches by default?

No.

What is the default coverage fail‑under threshold?

0

What is the default coverage report type?

term

Does coverage skip covered files by default?

No.

Does coverage skip empty files by default?

No.

What is the default faulthandler timeout?

0

Is strict config mode enabled by default?

No.

Are strict markers enabled by default?

No.

Clone this wiki locally