0
0
PyTesttesting~10 mins

setup.cfg configuration in PyTest - Test Execution Trace

Choose your learning style9 modes available
Test Overview

This test checks that pytest correctly reads configuration options from setup.cfg file. It verifies that a simple test runs and respects the configured markers and options.

Test Code - pytest
PyTest
import pytest

def test_example():
    assert 1 + 1 == 2

# setup.cfg content:
# [tool:pytest]
# markers = example_marker: mark test as example
# addopts = -v

# Run command:
# pytest --markers
# pytest test_sample.py
Execution Trace - 4 Steps
StepActionSystem StateAssertionResult
1pytest starts and reads setup.cfg configuration filepytest loads [tool:pytest] section with markers and addoptspytest configuration options are loaded successfullyPASS
2pytest discovers test_example function in test filetest_example function is found and ready to runtest function is detected by pytestPASS
3pytest runs test_example with verbosity enabled from addoptstest runs with verbose outputassert 1 + 1 == 2 is truePASS
4pytest finishes test run and reports resultstest report shows 1 passed test with verbose detailstest report matches expected output with configured verbosityPASS
Failure Scenario
Failing Condition: setup.cfg file is missing or has syntax errors, so pytest does not load configuration
Execution Trace Quiz - 3 Questions
Test your understanding
What does pytest read from setup.cfg before running tests?
AConfiguration options like markers and command line arguments
BTest function code
CTest results from previous runs
DPython interpreter version
Key Result
Using setup.cfg to configure pytest helps keep test options centralized and consistent without repeating command line arguments.