0
0
PyTesttesting~10 mins

Running tests by marker (-m) in PyTest - Test Execution Trace

Choose your learning style9 modes available
Test Overview

This test script uses pytest markers to categorize tests. It runs only tests marked with smoke and verifies their output.

Test Code - pytest
PyTest
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
Execution Trace - 5 Steps
StepActionSystem StateAssertionResult
1Test runner starts pytest with marker filter '-m smoke'pytest collects tests from the file, filtering only those marked with 'smoke'-PASS
2pytest runs test_addition() marked with 'smoke'Test environment ready, test_addition executesassert 1 + 1 == 2PASS
3pytest runs test_multiplication() marked with 'smoke'Test environment ready, test_multiplication executesassert 2 * 3 == 6PASS
4pytest does not collect test_subtraction() because it is marked 'regression', not 'smoke'test_subtraction is not collected or executed-PASS
5pytest finishes test run and reports resultsOnly tests with 'smoke' marker ran and passed2 tests passed, 0 tests skippedPASS
Failure Scenario
Failing Condition: A test marked with 'smoke' fails its assertion
Execution Trace Quiz - 3 Questions
Test your understanding
Which tests are executed when running 'pytest -m smoke'?
AOnly tests marked with 'smoke'
BAll tests regardless of marker
COnly tests marked with 'regression'
DNo tests are executed
Key Result
Using markers with '-m' lets you run specific groups of tests easily, helping focus on important test sets like smoke tests.