Skip to content

Instantly share code, notes, and snippets.

@D3f0
Created October 28, 2019 17:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save D3f0/29f7bd5a3d009633914ac3f55ba05f90 to your computer and use it in GitHub Desktop.
Save D3f0/29f7bd5a3d009633914ac3f55ba05f90 to your computer and use it in GitHub Desktop.
Check not Python breakpoints left behind
from pathlib import Path
from shlex import split
from subprocess import check_output
from typing import List
import pytest
def sh(cmd):
return check_output(split(cmd)).decode("utf-8").splitlines()
def get_versioned_py_files_in_HEAD() -> List[str]:
this_file = Path(__file__)
python_files_in_project = sh('git ls-files -- "*.py"')
python_paths_in_project = map(Path, python_files_in_project)
return [
str(pyfile)
for pyfile in python_paths_in_project
if pyfile.name != this_file.name
]
FILES = get_versioned_py_files_in_HEAD()
@pytest.mark.parametrize("pyfile", FILES, ids=FILES)
def test_no_breakpoints_left(pyfile):
lines = sh(f"git show HEAD:{pyfile}")
for n, line in enumerate(lines, start=1):
assert "from pdb" not in line, f"Breakpoint left in {pyfile}:{n}"
assert "set_trace()" not in line, f"Breakpoint left in {pyfile}:{n}"
assert "breakpoint()" not in line, f"Breakpoint left in {pyfile}:{n}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment