Test Overview
This test checks that pytest reads the pytest.ini configuration file correctly and applies the specified markers and options during test execution.
This test checks that pytest reads the pytest.ini configuration file correctly and applies the specified markers and options during test execution.
import pytest @pytest.mark.slow def test_example(): assert 1 + 1 == 2 # Run with: pytest -m slow
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Pytest starts and reads pytest.ini configuration file | pytest.ini file is present with markers and options defined | pytest recognizes the 'slow' marker from pytest.ini | PASS |
| 2 | Pytest collects tests and finds test_example marked with @pytest.mark.slow | Test suite includes test_example with 'slow' marker | Test is correctly marked as 'slow' | PASS |
| 3 | Pytest runs test_example with marker filter '-m slow' | Only tests marked 'slow' are executed | test_example runs and assertion 1 + 1 == 2 passes | PASS |
| 4 | Pytest finishes test run and generates report | Report shows test_example passed with marker 'slow' | Test report includes marker info and test passed status | PASS |
pytest.ini file in a pytest project?pytest.ini file is used to configure pytest behavior before running tests.pytest.ini. Dependency installation and report generation are handled elsewhere.pytest.ini?addopts to pass command-line options like -vv for verbosity level 2.addopts = -vv. [pytest]
verbosity = 2 uses an invalid key verbosity. [pytest]
verbosity: 2 uses wrong syntax with colon. [pytest]
addopts = --verbosity=2 uses an invalid flag.pytest.ini content:[pytest]
markers = slow: marks tests as slow
smoke: marks smoke tests
addopts = -rspytest with this configuration?markers section defines labels for tests but does not skip them automatically. The addopts = -rs option tells pytest to show extra summary info for skipped and failed tests.-rs increases output detail.pytest.ini file:[pytest] markers = regression addopts = --maxfail=3
ERROR: unknown option: --maxfail=3unknown option: --maxfail=3, meaning pytest does not recognize this option.addopts line should use -maxfail=3 instead is wrong because --maxfail requires two dashes. The pytest.ini file is missing the [pytest] header is wrong because the header is present. Markers must be defined after addopts in pytest.ini is wrong because order does not matter. The most common cause is an outdated pytest version that lacks support for --maxfail.pytest.ini to:slow and critical labels.test_*.py.pytest.ini configurations achieves all three correctly?python_files = test_*.py correctly.addopts = --maxfail=2 which stops after 2 failures but does not stop immediately on first failure. Options C and D add -x which stops after first failure, conflicting with requirement to stop after 2 failures. [pytest]
markers = slow
critical
python_files = test_*.py
addopts = -x --maxfail=2 lacks descriptions in markers.Pass the test and this pattern moves unknown