pytest.ini helps you set up rules and options for running tests easily. It saves time by keeping settings in one place.
0
0
pytest.ini configuration
Introduction
You want to run tests with specific options every time without typing them.
You need to ignore some files or folders during testing.
You want to change how pytest shows test results.
You want to add markers to group or skip tests.
You want to set the minimum pytest version required.
Syntax
PyTest
[pytest]
addopts = <options>
markers =
<marker1>: <description>
<marker2>: <description>
python_files = <pattern>
python_classes = <pattern>
python_functions = <pattern>
minversion = <version>
filterwarnings = <warning rules>The file is named pytest.ini and placed in your project root.
Indent marker descriptions with 4 spaces for readability.
Examples
This example runs tests verbosely and stops after 2 failures. It defines two markers and looks for test files starting with
test_.PyTest
[pytest] addopts = -v --maxfail=2 markers = slow: marks tests as slow smoke: marks smoke tests python_files = test_*.py minversion = 6.0
This example shortens tracebacks and ignores deprecation warnings during tests.
PyTest
[pytest] addopts = --tb=short filterwarnings = ignore::DeprecationWarning
Sample Program
This pytest.ini file sets verbose output, stops after one failure, defines a 'fast' marker, looks for test files starting with 'test_', and requires pytest version 6.0 or higher.
PyTest
[pytest] addopts = -v --maxfail=1 --tb=short markers = fast: marks fast tests python_files = test_*.py minversion = 6.0
OutputSuccess
Important Notes
Always place pytest.ini in the root folder of your project.
Use markers to organize tests and run specific groups easily.
Keep your addopts simple to avoid confusion when running tests manually.
Summary
pytest.ini stores test run settings in one file.
You can set options like verbosity, failure limits, and test file patterns.
Markers help label tests for easier selection.