0
0
Testing Fundamentalstesting~15 mins

Test progress reporting in Testing Fundamentals - Build an Automation Script

Choose your learning style9 modes available
Verify test progress reporting during test suite execution
Preconditions (2)
Step 1: Run the test suite
Step 2: Observe the progress output during test execution
Step 3: Verify that progress updates are shown after each test case completes
Step 4: Verify that the final progress shows 100% completion
✅ Expected Result: Progress updates are displayed after each test case, showing incremental completion percentage, and final output shows 100% completion.
Automation Requirements - pytest
Assertions Needed:
Verify progress output contains incremental progress updates
Verify final progress output shows 100% completion
Best Practices:
Use pytest hooks to capture progress output
Use assertions to check output correctness
Keep tests independent and clear
Automated Solution
Testing Fundamentals
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.

Common Mistakes - 3 Pitfalls
{'mistake': 'Not capturing printed output for progress verification', 'why_bad': 'Without capturing output, you cannot verify progress messages programmatically.', 'correct_approach': "Use pytest's capsys fixture to capture and assert printed progress output."}
Running all tests at once without intermediate progress updates
Hardcoding progress percentages without calculation
Bonus Challenge

Now add data-driven testing with 3 different inputs and report progress after each input test

Show Hint