Verify cost calculation of bugs at different development stages
Preconditions (2)
✅ Expected Result: The function returns correct costs: requirements=1, design=5, development=10, testing=20, production=100
import pytest def calculate_bug_cost(stage: str) -> int: costs = { 'requirements': 1, 'design': 5, 'development': 10, 'testing': 20, 'production': 100 } return costs.get(stage, 0) @pytest.mark.parametrize('stage,expected_cost', [ ('requirements', 1), ('design', 5), ('development', 10), ('testing', 20), ('production', 100) ]) def test_calculate_bug_cost(stage, expected_cost): cost = calculate_bug_cost(stage) assert cost == expected_cost, f"Cost for stage '{stage}' should be {expected_cost} but got {cost}"
This test uses pytest with parameterization to check the bug cost at each stage.
The calculate_bug_cost function returns the cost based on a dictionary lookup.
The test test_calculate_bug_cost runs once for each stage and asserts the returned cost matches the expected value.
Assertions include messages to help identify failures clearly.
Now add data-driven testing with 3 additional invalid stage inputs and verify the cost is zero
Requirements: 1x, Design: 5x, Testing: 10x, Production: 50xThe cost to fix bugs is the same at all stages of development.Pass the test and this pattern moves unknown