Python · testing
trivially-true-assertion
python:trivially-true-assertion Assertions should depend on behavior rather than echoing values supplied by the test.
- Code
- SARJ064
- Default
- error
- Fix
- none
- Languages
- python
Why
Constructor keyword echoes and equivalent tautologies cannot reveal an application defect.
Fix
Assert a transformation, validation result, or other value produced independently of the fixture literal.
Before / after
Executed by this rule’s unit tests.
Before
Assertion repeats a constructor keyword
def test_user():
user = User(name="Ada")
assert user.name == "Ada"
After
Assertion checks a derived value
def test_user():
user = User(name="Ada Lovelace")
assert user.initials == "AL"
Limits
- Literal-only assertions owned by Ruff or SARJ057 are excluded.
- Constructor echoes with evidence of field coercion are excluded.