Skip to content

no-provably-dead-mock-configuration

Remove mock behavior configuration proven unable to affect a test.

Why

A mock behavior value is dead when a same-path write replaces it before observation, or when a terminal exact-path assertion proves the configured mock was never called.

Fix

Delete the earlier overwritten configuration, or place the intended action before reconfiguration; delete behavior configuration contradicted by a terminal never-called assertion.

Examples

Before — flagged Mock return value is overwritten before use
tests/test_billing.py
from unittest.mock import Mock
def test_charge():
charge = Mock()
charge.return_value = 1
charge.return_value = 2
assert charge() == 2
After — preferred Test uses each configured value
tests/test_billing.py
from unittest.mock import Mock
def test_charge():
charge = Mock()
charge.return_value = 1
assert charge() == 1
charge.return_value = 2
assert charge() == 2

Formerly: unused-mock-setup