Test Overview
This test script uses pytest markers to categorize tests. It runs only tests marked with smoke and verifies their output.
This test script uses pytest markers to categorize tests. It runs only tests marked with smoke and verifies their output.
import pytest @pytest.mark.smoke def test_addition(): assert 1 + 1 == 2 @pytest.mark.regression def test_subtraction(): assert 5 - 3 == 2 @pytest.mark.smoke def test_multiplication(): assert 2 * 3 == 6 # Command to run: pytest -m smoke
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test runner starts pytest with marker filter '-m smoke' | pytest collects tests from the file, filtering only those marked with 'smoke' | — | PASS |
| 2 | pytest runs test_addition() marked with 'smoke' | Test environment ready, test_addition executes | assert 1 + 1 == 2 | PASS |
| 3 | pytest runs test_multiplication() marked with 'smoke' | Test environment ready, test_multiplication executes | assert 2 * 3 == 6 | PASS |
| 4 | pytest does not collect test_subtraction() because it is marked 'regression', not 'smoke' | test_subtraction is not collected or executed | — | PASS |
| 5 | pytest finishes test run and reports results | Only tests with 'smoke' marker ran and passed | 2 tests passed, 0 tests skipped | PASS |
-m option do when running pytest?-m option-m option runs only tests that have the specified marker label.slow?-m, not --marker or others.pytest -m slow to run tests marked as slow.fast and db:
@pytest.mark.fast def test_a(): pass @pytest.mark.db def test_b(): pass @pytest.mark.fast def test_c(): passWhat tests run with the command
pytest -m "fast and not db"?fast AND NOT marked with db.test_a and test_c have fast only; test_b has db only.pytest -m slow but no tests run, even though some tests have @pytest.mark.slow. What is the most likely cause?pytest.ini to avoid warnings and ensure correct filtering.api, ui, and db. You want to run tests that are either api or ui, but not db. Which command achieves this?api or ui together.(api or ui) and excludes db with and not db.Pass the test and this pattern moves unknown