Skip to content

Python · testing

test-phase-label-comment

python:test-phase-label-comment

Tests must not use bare Arrange, Act, Assert, Given, When, or Then phase comments.

Code
SARJ089
Default
error
Fix
none
Languages
python

Why

Phase labels narrate test structure without explaining behavior and often indicate that a test needs clearer names or smaller units.

Fix

Delete the label; if the phases remain hard to follow, extract a named helper or split the test.

Before / after

Executed by this rule’s unit tests.

Before

Bare phase label

tests/test_widget.py · focus
def test_widget():
    # Arrange
    widget = make_widget()
    assert widget

After

Comment explains a consequence

tests/test_widget.py · focus
def test_widget():
    # Then the retry loop would spin forever.
    assert works()

Limits

  • Only standalone comments in recognized test files are checked; nested literal comments and trailing comments are excluded.
  • Comments containing words beyond the bounded phase-label grammar are preserved.