Skip to content

Commit

Permalink
Merge pull request #7 from aviv/master
Browse files Browse the repository at this point in the history
Detect `pdb.set_trace`, add test for `set_trace` calls
  • Loading branch information
vyahello authored Jan 21, 2023
2 parents c30e661 + 93d48b4 commit bb8d67a
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
3 changes: 3 additions & 0 deletions flake8_debug/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ def visit_Call(self, node: ast.Call) -> None:
if (
isinstance(node.func, ast.Name)
and node.func.id == error.func_name
) or (
isinstance(node.func, ast.Attribute)
and node.func.attr == error.func_name
):
self.issues.append((node.lineno, node.col_offset, error().msg))

Expand Down
2 changes: 1 addition & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
black==22.12.0
flake8==4.0.1
flake8>=4.0.1
pytest==7.0.1
pytest-cov==3.0.0
coverage==5.3
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
flake8==4.0.1
flake8>=4.0.1
astpretty==2.1.0
17 changes: 17 additions & 0 deletions tests/flake8_debug_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
PrintError,
BreakpointError,
BreakpointHookError,
PdbError,
)
from flake8_debug.plugin import NoDebug

Expand Down Expand Up @@ -77,3 +78,19 @@ def test_present_multiple_breakpointhooks():
) == tuple(
_out(line, column=5, err=BreakpointHookError()) for line in (3, 4)
)


def test_present_set_trace():
assert _plugin_results(
'def f():\n import pdb\n pdb.set_trace()'
) == (
_out(line=3, column=5, err=PdbError()),
)


def test_present_bare_set_trace():
assert _plugin_results(
'def f():\n from pdb import set_trace\n set_trace()'
) == (
_out(line=3, column=5, err=PdbError()),
)

0 comments on commit bb8d67a

Please sign in to comment.