Test Overview
This test checks that a pytest configuration file standardizes the test behavior by setting a fixed seed for randomness and a common timeout. It verifies that the test runs consistently with these settings.
This test checks that a pytest configuration file standardizes the test behavior by setting a fixed seed for randomness and a common timeout. It verifies that the test runs consistently with these settings.
import pytest import random def test_random_number(): # The seed is set in pytest.ini to ensure consistent random numbers num = random.randint(1, 100) assert num == 42 # Expected fixed number due to seed # pytest.ini content: # [pytest] # addopts = --timeout=5 # random_seed = 12345 # conftest.py content: # import random # def pytest_configure(config): # seed = config.getoption('random_seed', default=12345) # random.seed(seed)
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test runner starts pytest with configuration loaded from pytest.ini and conftest.py | pytest.ini sets random_seed=12345 and timeout=5 seconds; conftest.py sets random.seed(12345) | — | PASS |
| 2 | pytest runs test_random_number function | random.seed is set to 12345, so random.randint(1, 100) returns a fixed number | assert num == 42 | PASS |
| 3 | Test completes within the configured timeout of 5 seconds | Test finishes quickly without timeout | — | PASS |
pytest.ini configuration file important for test behavior?pytest.ini define settings that control how tests run, such as markers, test paths, or warnings.pytest.ini to standardize test selection?[pytest] and the key is markers with an equals sign and description.markers = slow: marks tests as slow, which matches pytest documentation syntax.pytest.ini content:[pytest] addopts = -v --maxfail=2
pytest on a test suite with 5 failing tests?addopts options-v means verbose output. The option --maxfail=2 means pytest stops after 2 failures.-v.filterwarnings = ignore::DeprecationWarning in pytest.ini but still see deprecation warnings during test runs. What is the likely cause?filterwarningsfilterwarnings under the [pytest] section in pytest.ini.filterwarnings option is misspelled or misplaced in the config file. -> Option B@pytest.mark.slow are skipped by default unless explicitly included. Which pytest.ini configuration achieves this standardized behavior?-m 'not slow' to run tests not marked slow.addopts = -m 'not slow', which tells pytest to exclude slow tests unless overridden.Pass the test and this pattern moves unknown