0
0
PyTesttesting~10 mins

Command-line options in PyTest - Test Execution Trace

Choose your learning style9 modes available
Test Overview

This test runs a simple pytest test function using the command-line option -v for verbose output. It verifies that the test passes and the verbose output is shown.

Test Code - pytest
PyTest
import pytest

def test_addition():
    assert 2 + 3 == 5

# To run this test with verbose output, use:
# pytest -v test_file.py
Execution Trace - 5 Steps
StepActionSystem StateAssertionResult
1Test runner starts pytest with command-line option '-v' for verbose outputTerminal shows pytest starting with verbose mode enabled-PASS
2Pytest discovers the test function 'test_addition'Test function is found and ready to run-PASS
3Pytest runs 'test_addition' functionTest executes the assertion 2 + 3 == 5Assert that 2 + 3 equals 5PASS
4Pytest outputs verbose test result lineTerminal shows 'test_addition PASSED' with test nameCheck that verbose output includes test name and PASSED statusPASS
5Pytest finishes test run and shows summaryTerminal shows summary with 1 passed testVerify summary reports 1 passed testPASS
Failure Scenario
Failing Condition: The assertion in test_addition fails (e.g., 2 + 3 != 5)
Execution Trace Quiz - 3 Questions
Test your understanding
What does the '-v' option do when running pytest?
ARuns tests in silent mode
BSkips all tests
CShows detailed test names and results
DRuns tests twice
Key Result
Using command-line options like '-v' helps testers see detailed test results, making it easier to understand which tests ran and their outcomes.