Test Overview
This test checks that a custom marker slow is registered in pytest.ini and can be used to mark tests. It verifies that pytest recognizes the marker and runs the test accordingly.
This test checks that a custom marker slow is registered in pytest.ini and can be used to mark tests. It verifies that pytest recognizes the marker and runs the test accordingly.
import pytest @pytest.mark.slow def test_example(): assert 1 + 1 == 2 # pytest.ini content: # [pytest] # markers = # slow: marks tests as slow to run
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test runner starts pytest and reads pytest.ini configuration | pytest.ini file is loaded with 'slow' marker registered | — | PASS |
| 2 | pytest discovers test_example function marked with @pytest.mark.slow | Test function is found with 'slow' marker attached | — | PASS |
| 3 | pytest runs test_example | Test executes the assertion 1 + 1 == 2 | Assert that 1 + 1 equals 2 | PASS |
| 4 | pytest reports test result | Test passed without errors, marker recognized | Test marked as 'slow' is accepted and runs successfully | PASS |
pytest.ini file?pytest.ini prevents warnings about unknown markers and keeps tests organized.slow in pytest.ini?[markers] section in pytest.ini.= with a description, e.g., slow = marks tests as slow.pytest.ini content:
[markers] api = marks tests as api tests slow = marks tests as slowWhat happens if you run
pytest -m slow?-m option runs tests matching the given marker name.slow is registered and used, pytest -m slow runs only tests marked with @pytest.mark.slow.pytest.ini:
[markers] fast marks tests as fastBut when running tests, pytest shows a warning about unknown marker 'fast'. What is the problem?
= between the marker name and its description.fast marks tests as fast lacks '=', so pytest treats 'fast' as unknown marker.pytest.ini: db for database tests and ui for user interface tests. Which pytest.ini content correctly registers both markers?[markers] section, not [pytest].= with a description, e.g., db = marks tests as database tests.db and ui markers are listed on separate lines with descriptions.Pass the test and this pattern moves unknown