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 |