Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Direct assert rule to ignore asserts in test functions #639

Merged
merged 1 commit into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions precli/rules/python/stdlib/assert.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]),
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# level: NONE
def test_foobar(a: str = None):
assert a is not None
return f"Hello {a}"


foobar(None)
1 change: 1 addition & 0 deletions tests/unit/rules/python/stdlib/assert/test_assert.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def test_rule_meta(self):
"filename",
[
"assert.py",
"assert_test_func.py",
],
)
def test(self, filename):
Expand Down