import pytest
import io
import sys
def test_case_1():
assert True
def test_case_2():
assert True
def test_case_3():
assert True
def test_case_4():
assert True
def test_case_5():
assert True
class ProgressReporter:
def __init__(self):
self.progress_updates = []
def pytest_runtest_logreport(self, report):
if report.when == 'call' and report.passed:
self.progress_updates.append(f"Test {report.nodeid} passed")
@pytest.fixture
def progress_reporter():
reporter = ProgressReporter()
return reporter
def test_progress_reporting(progress_reporter, capsys):
# Run all test cases manually to simulate progress
test_functions = [test_case_1, test_case_2, test_case_3, test_case_4, test_case_5]
total = len(test_functions)
for i, test_func in enumerate(test_functions, 1):
test_func()
progress = (i / total) * 100
print(f"Progress: {progress:.0f}%")
captured = capsys.readouterr()
lines = captured.out.strip().split('\n')
# Check that progress increments correctly
expected_progress = [f"Progress: {int((i/total)*100)}%" for i in range(1, total+1)]
assert lines == expected_progress, f"Expected progress lines {expected_progress}, got {lines}"
# Check final progress is 100%
assert lines[-1] == "Progress: 100%"
This test script defines 5 simple test cases that always pass.
The test_progress_reporting function runs each test case one by one, printing the progress percentage after each test completes.
We capture the printed output using capsys fixture to verify the progress messages.
Assertions check that the progress messages increment correctly and that the final progress is 100%.
This simulates progress reporting during a test suite run.