Test Overview
This test checks that a pytest marker named slow is properly registered and can be used to mark a test. It verifies that the marker is recognized and the test runs successfully.
This test checks that a pytest marker named slow is properly registered and can be used to mark a test. It verifies that the marker is recognized and the test runs successfully.
import pytest @pytest.mark.slow def test_example(): assert 1 + 1 == 2
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Pytest starts and loads test modules | Pytest environment initialized with registered markers | — | PASS |
| 2 | Pytest discovers test_example marked with @pytest.mark.slow | Test function test_example is found with marker 'slow' | Check marker 'slow' is registered and recognized | PASS |
| 3 | Pytest runs test_example | Test executes the assertion 1 + 1 == 2 | Assert that 1 + 1 equals 2 | PASS |
| 4 | Pytest reports test_example as passed | Test suite shows test_example passed with marker 'slow' | — | PASS |
pytest.ini?pytest.ini to inform pytest about custom markers.slow in pytest.ini?pytest.ini content and test code, what will be the result when running pytest -m slow?
[pytest] markers = slow: marks tests as slow
import pytest
@pytest.mark.slow
def test_example():
assert True
def test_fast():
assert True
-m slow option-m slow option runs only tests marked with @pytest.mark.slow.test_example is marked with @pytest.mark.slow, test_fast is not.database to your tests but pytest shows a warning: PytestUnknownMarkWarning. What is the most likely cause and how to fix it?pytest.ini.database marker under the [pytest] section in pytest.ini to register it and remove the warning.api but skip those marked as slow. Your pytest.ini contains:
[pytest]
markers =
api: marks API tests
slow: marks slow tests
Which command correctly runs only api tests excluding slow tests?-m option accepts boolean expressions combining markers using and, or, and not.api but not slow, so expression is api and not slow.Pass the test and this pattern moves unknown