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

fixed missing coverage for one-line lambdas in 3.11 #60

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
6 changes: 4 additions & 2 deletions src/slipcover/slipcover.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ def counter_total(self: Counter) -> int:
_op_RETURN_GENERATOR = dis.opmap["RETURN_GENERATOR"]

def findlinestarts(co: types.CodeType):
for off, line in dis.findlinestarts(co):
if line and co.co_code[off] not in (_op_RESUME, _op_RETURN_GENERATOR):
last_line = None
for off, _, line in co.co_lines():
if line and line != last_line and co.co_code[off] not in (_op_RESUME, _op_RETURN_GENERATOR):
last_line = line
yield off, line

else:
Expand Down
29 changes: 29 additions & 0 deletions tests/test_coverage.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,35 @@ def foo(n):
assert [] == cov['missing_lines']


def test_oneline_lambda():
sci = sc.Slipcover()

base_line = current_line()
def foo(n):
n = (
lambda: n
)()

unused = \
lambda: 24
return n

X = foo(42)

sci.instrument(foo)
dis.dis(foo)

assert X == foo(42)

cov = sci.get_coverage()
assert {simple_current_file()} == cov['files'].keys()

cov = cov['files'][simple_current_file()]
assert [2, 3, 6, 8] == [l-base_line for l in cov['executed_lines']]
assert [7] == cov['missing_lines']



def test_exception():
sci = sc.Slipcover()

Expand Down
Loading