Python · testing
interaction-only-test
python:interaction-only-test Tests should verify outcomes, not only mock interaction bookkeeping.
- Code
- SARJ063
- Default
- error
- Fix
- none
- Languages
- python
Why
Interaction-only assertions pin implementation call sequences without proving useful behavior.
Fix
Assert returned data, persisted state, emitted output, or another observable outcome.
Before / after
Executed by this rule’s unit tests.
Before
Test checks only collaborator calls
def test_notify():
notify(mailer, audit, user)
mailer.send.assert_called_once_with(user.email)
audit.record.assert_called_once_with("notified")
After
Test checks the returned notification
def test_notify():
result = notify(mailer, audit, user)
mailer.send.assert_called_once_with(user.email)
audit.record.assert_called_once_with("notified")
assert result.status == "sent"
Limits
- Only collected tests with multiple mock targets and no outcome assertion are reported.