Your question is Debugging and Improving Test Code. Take a moment with it on the right.
Talk me through your thinking if you like. When you're confident, submit your answer and I'll grade it like a real screen (7/10 or better passes).
At ING Hubs Spain, this pytest suite tests a function that calculates overdraft fees for a banking app. QA flagged it as "flaky" - it passes locally but fails intermittently in CI.
account_balance = {"value": 1000}
def test_no_fee_when_balance_positive():
account_balance["value"] = 1000
fee = calculate_overdraft_fee(account_balance["value"])
assert fee == 0
def test_fee_applied_when_overdrawn():
account_balance["value"] -= 1200
fee = calculate_overdraft_fee(account_balance["value"])
time.sleep(1)
assert fee == 35
def test_large_overdraft_capped_fee():
account_balance["value"] -= 5000
fee = calculate_overdraft_fee(account_balance["value"])
assert fee == 35
def test_admin_override_no_fee(mocker):
mocker.patch("banking.is_admin_account", return_value=True)
fee = calculate_overdraft_fee(account_balance["value"])
assert fee == 0
Analyze this test suite. What issues do you see, and how would you address each one?