diff --git a/precli/rules/python/stdlib/assert.py b/precli/rules/python/stdlib/assert.py index f1bf6b5f..11ee206b 100644 --- a/precli/rules/python/stdlib/assert.py +++ b/precli/rules/python/stdlib/assert.py @@ -79,8 +79,9 @@ def __init__(self, id: str): ) def analyze_assert(self, context: dict) -> Optional[Result]: - return Result( - rule_id=self.id, - artifact=context["artifact"], - location=Location(context["node"]), - ) + if not context["symtab"].name().startswith("test_"): + return Result( + rule_id=self.id, + artifact=context["artifact"], + location=Location(context["node"]), + ) diff --git a/tests/unit/rules/python/stdlib/assert/examples/assert_test_func.py b/tests/unit/rules/python/stdlib/assert/examples/assert_test_func.py new file mode 100644 index 00000000..94c97a69 --- /dev/null +++ b/tests/unit/rules/python/stdlib/assert/examples/assert_test_func.py @@ -0,0 +1,7 @@ +# level: NONE +def test_foobar(a: str = None): + assert a is not None + return f"Hello {a}" + + +foobar(None) diff --git a/tests/unit/rules/python/stdlib/assert/test_assert.py b/tests/unit/rules/python/stdlib/assert/test_assert.py index df65a396..b1cb5b77 100644 --- a/tests/unit/rules/python/stdlib/assert/test_assert.py +++ b/tests/unit/rules/python/stdlib/assert/test_assert.py @@ -41,6 +41,7 @@ def test_rule_meta(self): "filename", [ "assert.py", + "assert_test_func.py", ], ) def test(self, filename):