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.
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.
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
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test runner starts subprocess to run 'pytest test_sample.py' without extra options | Command line runs pytest with default options from pytest.ini addopts | — | PASS |
| 2 | Pytest loads configuration and applies addopts '-v' for verbose output | Pytest runs tests with verbose output enabled | — | PASS |
| 3 | Test subprocess completes and returns output | Captured stdout includes verbose test names and statuses | Check that '::' is in stdout (verbose indicator) and return code is 0 | PASS |
addopts setting in a pytest.ini file?addopts role in pytest.iniaddopts is used to provide default command-line options so you don't have to type them every time.addopts.pytest.ini using addopts?pytest.ini, options are set as key = value pairs under [pytest] section.--maxfail=3 --verbose.pytest.ini content:[pytest] addopts = --maxfail=2 --tb=short
pytest tests/ without extra options?--maxfail=2 and --tb=short set limits on failures and traceback style by default.addopts = --maxfail=1 --verbose to pytest.ini but pytest still runs all tests without stopping early. What is the likely cause?pytest.ini if it is in the current directory or a parent directory of the test run.pytest.ini is misplaced, addopts settings are ignored and default pytest behavior occurs.addopts line in pytest.ini achieves this correctly?--cov=src with equals sign; maxfail uses --maxfail=5.--stop are incorrect.Pass the test and this pattern moves unknown