0
0
PyTesttesting~10 mins

Addopts for default options in PyTest - Test Execution Trace

Choose your learning style9 modes available
Test Overview

This test verifies that pytest runs with default options specified in the pytest.ini file using the addopts setting. It checks that verbose output is enabled by default due to -v from addopts.

Test Code - PyTest
PyTest
import subprocess

def test_pytest_addopts_default():
    # Run pytest with no extra options, relying on addopts in pytest.ini
    result = subprocess.run(['pytest', 'test_sample.py'], capture_output=True, text=True)
    # Check that verbose output is present due to -v from addopts
    assert "::" in result.stdout
    assert result.returncode == 0
Execution Trace - 3 Steps
StepActionSystem StateAssertionResult
1Test runner starts subprocess to run 'pytest test_sample.py' without extra optionsCommand line runs pytest with default options from pytest.ini addopts-PASS
2Pytest loads configuration and applies addopts '-v' for verbose outputPytest runs tests with verbose output enabled-PASS
3Test subprocess completes and returns outputCaptured stdout includes verbose test names and statusesCheck that '::' is in stdout (verbose indicator) and return code is 0PASS
Failure Scenario
Failing Condition: The addopts setting in pytest.ini is missing or incorrect, so verbose output is not enabled by default
Execution Trace Quiz - 3 Questions
Test your understanding
What does the addopts setting in pytest.ini do in this test?
AIt adds default command-line options like '-v' when pytest runs
BIt disables all command-line options
CIt changes the test file name
DIt skips tests automatically
Key Result
Using addopts in pytest.ini helps set default command-line options so tests run consistently without needing to specify options every time.