no-assert

Try in Playground
python-best-practicesBest PracticeWarning

0

No tags

No CWE or CVE

Avoid having assert statements in code as they are not being used when . This rule does not apply to test files (e.g., file ending with _test.py).

Pattern Rule: assert ${arguments}


no-assert

How to write a rule
function visit(pattern, filename, code) {
  if(filename.includes("_test.py") || filename.startsWith("test_")) {
    return;
  }

  const error = buildError(pattern.start.line, pattern.start.col, pattern.end.line, pattern.end.col, "No assert in production code", "WARN", "code_style");
  const edit = buildEditRemove(pattern.start.line, pattern.start.col, pattern.end.line, pattern.end.col);
  const fix = buildFix("remove assert", [edit]);
  addError(error.addFix(fix));
}

assert.py

Expected test result: has error

Use of assert in non-test code

def foo(bar):
  assert bar

assert_test.py

Expected test result: no error

Use of assert in test code

def foo(bar):
  assert bar
Add comment

Log in to add a comment


    Be the first one to leave a comment!

Codiga Logo
Codiga Hub
  • Rulesets
  • Explore
  • Cookbooks
  • Playground
soc-2 icon

We are SOC-2 Compliance Certified

G2 high performer medal

Codiga – All rights reserved 2022.