0
0
PyTesttesting~10 mins

pyproject.toml configuration in PyTest - Test Execution Trace

Choose your learning style9 modes available
Test Overview

This test checks if pytest correctly reads configuration from pyproject.toml to set test markers and options. It verifies that a test marked as smoke runs and passes.

Test Code - pytest
PyTest
import pytest

@pytest.mark.smoke
def test_example():
    assert 1 + 1 == 2

# Run command:
# pytest -m smoke

# pyproject.toml content:
# [tool.pytest.ini_options]
# markers = ["smoke: mark test as smoke test"]
# addopts = "-m smoke"
Execution Trace - 5 Steps
StepActionSystem StateAssertionResult
1Test runner starts pytestpytest reads pyproject.toml configuration file-PASS
2pytest applies ini_options from pyproject.toml, enabling 'smoke' marker and '-m smoke' optionpytest is configured to run only tests marked with 'smoke'-PASS
3pytest discovers test_example functiontest_example is marked as 'smoke'-PASS
4pytest runs test_exampletest_example executes assert 1 + 1 == 2assert 2 == 2PASS
5pytest reports test_example passed with 'smoke' markerTest report shows 1 passed test with smoke markertest count and marker correctnessPASS
Failure Scenario
Failing Condition: pyproject.toml is missing or misconfigured, so pytest does not recognize the 'smoke' marker or the '-m smoke' option
Execution Trace Quiz - 3 Questions
Test your understanding
What does pytest read from pyproject.toml to recognize the 'smoke' marker?
AThe [pytest] section with 'testpaths'
BThe [tool.pytest.ini_options] section with 'markers' list
CThe [tool.black] section for formatting
DThe [tool.isort] section for imports
Key Result
Using pyproject.toml to configure pytest markers and options helps keep test settings centralized and consistent without command line flags.