Closed di closed 4 months ago
Hi, thank you for reporting it, and sorry I didn't get to it any sooner.
I am not sure this can be fixed on Slipcover's side... Slipcover needs to instrument the code to measure coverage, but automat requires it not to be instrumented. This is the code in automat/_methodical.py
:
def _empty():
pass
def _docstring():
"""docstring"""
def assertNoCode(inst, attribute, f):
# The function body must be empty, i.e. "pass" or "return None", which
# both yield the same bytecode: LOAD_CONST (None), RETURN_VALUE. We also
# accept functions with only a docstring, which yields slightly different
# bytecode, because the "None" is put in a different constant slot.
# Unfortunately, this does not catch function bodies that return a
# constant value, e.g. "return 1", because their code is identical to a
# "return None". They differ in the contents of their constant table, but
# checking that would require us to parse the bytecode, find the index
# being returned, then making sure the table has a None at that index.
if f.__code__.co_code not in (_empty.__code__.co_code,
_docstring.__code__.co_code):
raise ValueError("function body must be empty")
I don't see how this can be fixed on SlipCover's side...
I use a library, automat that has some runtime assumptions about whether certain functions have function bodies or not.
When I run my tests with
pytest
andcoverage
, it works as expected:When I run it with
slipcover
, it causes these assumptions to fail:A minimally reproducing example is below
requirements.txt
:foo.py
:test_something.py
: