Skip to content

Conversation

@xirafa
Copy link

@xirafa xirafa commented Dec 12, 2024

For issue #59 :

One-line lambdas are missing coverage probes (3.11).

If a lambda is not executed, we don't get any indication.
This is due to interplay between dis.findlinestarts() which removes duplicated, and slipcover.findlinestarts() which ignores noop-like opcode of RESUME and RETURN_GENERATOR.

@jaltmayerpizzorno
Copy link
Collaborator

Thank you for your contribution! Any chance you'd be willing to add a test that replicates the issue?

@xirafa
Copy link
Author

xirafa commented Dec 12, 2024

I added a simple test but apparently the current coverage report does report unexecuted lambdas as actually executed (probably due to covering the entire statement which defines the lambda).

Delving into this requires a bit more time than I have now - but probably someone might want to examine this further.

See the updated PR with the new test.

@jaltmayerpizzorno
Copy link
Collaborator

Python 3.11 tags the code that defines the lambda with the same line number as the lambda itself:

104          78 NOP
             80 PUSH_NULL
             82 LOAD_CONST               3 (<built-in function signal>)
             84 LOAD_CONST               6 (<capsule object NULL at 0x105fa8960>)
             86 PRECALL                  1
             90 CALL                     1
            100 POP_TOP
            102 LOAD_CONST               2 (<code object <lambda> at 0x106013930, file "/Users/juan/project/slipcover2/tests/test_coverage.py", line 104>)
            104 MAKE_FUNCTION            0
            
[...]

Disassembly of <code object <lambda> at 0x106013930, file "/Users/juan/project/slipcover2/tests/test_coverage.py", line 104>:
104           0 RESUME                   0
              2 LOAD_CONST               1 (24)
              4 RETURN_VALUE

With this, unfortunately, SlipCover can't differentiate between defining the lambda and executing it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants