Why do pytest configuration files like pytest.ini help standardize test behavior across different environments?
Think about how consistent settings affect test results when running on different machines.
Configuration files set common options like markers, test paths, or logging levels. This makes tests behave the same way everywhere, preventing surprises.
Given this pytest configuration and test code, what will be the output when running pytest?
[pytest] addopts = -v # test_sample.py import pytest def test_pass(): assert True def test_fail(): assert False
Look at the addopts = -v line and what -v means in pytest.
The -v option makes pytest show detailed test results. Both tests run, one passes and one fails, and output is verbose.
Which assertion correctly verifies that pytest respects the markers defined in pytest.ini during test collection?
[pytest] markers = slow: marks tests as slow # test_marked.py import pytest @pytest.mark.slow def test_example(): assert True
Think about how pytest exposes configuration values programmatically.
The getini method reads config values like markers. This assertion checks if 'slow' is registered as a marker.
A test passes on one machine but fails on another. Both run the same code but only one has a pytest.ini file setting addopts = --maxfail=1. What is the likely cause?
Consider what --maxfail=1 does to test execution.
The config stops tests after the first failure. Without it, all tests run, so more failures show up on the other machine.
In pytest, how does defining fixtures in conftest.py help standardize test behavior across multiple test files?
Think about how pytest discovers fixtures and applies them automatically.
Placing fixtures in conftest.py makes them available to all tests in that directory tree without imports, standardizing setup.