Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork32k
Open
Description
Bug report
Bug description:
I'm usingcoverage
andpytest-cov
in CI to measure the line coverage of the unittests. It is achieved by registering a trace function withsys.settrace.
However, after binsecting my unittests, I found that when aRecursionError
is raised, the system trace function will be cleared. That will cause a warning emitted bycoverage
:
~/Projects/cpython/venv/lib/python3.15t/site-packages/coverage/pytracer.py:355: CoverageWarning: Trace function changed, data is likely wrong: None != <bound method PyTracer._trace of <PyTracer at 0x200021dcc20: 2076 data points in 11 files>> (trace-changed) self.warn(
Reproducible code:
importsysdeftracer(*args,**kwargs):passdeffactorial(n:int)->int:"""Calculate the factorial of a number."""ifn<=1:return1returnn*factorial(n-1)sys.settrace(tracer)assertsys.gettrace()istracersys.setrecursionlimit(64)assertsys.gettrace()istracertry:_=factorial(100)exceptRecursionError:passassertsys.gettrace()isNone
REPL Output:
# Add a code block here, if required$python3Python3.13.3 (main,Apr82025,13:54:08) [Clang16.0.0 (clang-1600.0.26.6)]ondarwinType"help","copyright","credits"or"license"formoreinformation.>>>importsys>>>deftracer(*args,**kwargs):...pass...>>>deffactorial(n):...ifn<=1:...return1...returnn*factorial(n-1)...>>>sys.settrace(tracer)>>>sys.gettrace()istracerTrue>>>sys.setrecursionlimit(64)>>> _=factorial(100)Traceback (mostrecentcalllast):File"<python-input-6>",line1,in<module>_=factorial(100)File"<python-input-2>",line4,infactorialreturnn*factorial(n-1)~~~~~~~~^^^^^^^File"<python-input-2>",line4,infactorialreturnn*factorial(n-1)~~~~~~~~^^^^^^^File"<python-input-2>",line4,infactorialreturnn*factorial(n-1)~~~~~~~~^^^^^^^ [Previouslinerepeated51moretimes]File"<python-input-2>",line1,infactorialdeffactorial(n):RecursionError:maximumrecursiondepthexceeded>>>sys.gettrace()isNoneTrue
CPython versions tested on:
CPython main branch
Operating systems tested on:
macOS