Skip to content

Prohibit self.assertRaisesMessage with empty string #45

@GitRon

Description

@GitRon

User Story

As a Django developer,
I want the linter boa restrictor to flag any usage of self.assertRaisesMessage with an empty string as the expected message,
so that tests enforce meaningful error messages and avoid false positives.


Acceptance Criteria

  1. Detection

    • The linter must detect calls to self.assertRaisesMessage where the second argument is an empty string ("").
    • Example (should be flagged):
      self.assertRaisesMessage(ValueError, "")
  2. Non-Detection (Valid Cases)

    • Calls where the second argument is a non-empty string must not be flagged.
      self.assertRaisesMessage(ValueError, "Invalid input")
    • Calls to other assert* methods (e.g., self.assertRaises, self.assertEqual) must not be flagged.
    • Calls to assertRaisesMessage outside of Django’s TestCase context may still be flagged (depending on implementation scope), but only empty strings should trigger the rule.
  3. Error Message

    • The linter should produce a clear error message such as:
      boa restrictor: Do not use assertRaisesMessage with an empty string as the expected message.
      
  4. Configurability

    • The rule must be part of the Django-only ruleset and enabled only when Django checks are active.
  5. Fix Guidance

    • Documentation or autofix (if supported) should suggest replacing the empty string with either a meaningful message or using self.assertRaises if message matching is unnecessary.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions