Skip to content

Commit 4edc0ba

Browse files
author
Lucas Haupt
committed
Add workaround fix for faulty memory_profiler module
The memory profiler only reports Exceptions when it should report all Exceptions that inherit from BaseExceptions. This is ultimately reworked in a PR incorporating a simplified memory profiler module into the codebase that fixes not only this issue but also gives the possibility of getting measurements for failing tests. This workaround uses return values to work around the issue. This way pytest-monitor can check for BaseExceptions and act accordingly. Like described earlier the ultimate goal should probably be to replace the whole memory profiler as proposed in this PR: CFMTech#82
1 parent 653d746 commit 4edc0ba

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

pytest_monitor/pytest_monitor.py

+15-1
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,13 @@ def wrapped_function():
228228
except Exception:
229229
raise
230230
except BaseException as e:
231+
# this is a workaround to fix the faulty behavior of the memory profiler
232+
# that only catches Exceptions but should catch BaseExceptions instead
233+
# actually BaseExceptions should be raised here, but without modifications
234+
# of the memory profiler (like proposed in PR
235+
# https://github.com/CFMTech/pytest-monitor/pull/82 ) this problem
236+
# can just be worked around like so (BaseException can only come through
237+
# this way)
231238
return e
232239

233240
def prof():
@@ -241,7 +248,14 @@ def prof():
241248
setattr(pyfuncitem, "monitor_results", True)
242249

243250
if not PYTEST_MONITORING_ENABLED:
244-
wrapped_function()
251+
try:
252+
# this is a workaround to fix the faulty behavior of the memory profiler
253+
# that only catches Exceptions but should catch BaseExceptions instead
254+
e = wrapped_function()
255+
if isinstance(e, BaseException):
256+
raise e
257+
except BaseException:
258+
raise
245259
else:
246260
if not pyfuncitem.session.config.option.mtr_disable_gc:
247261
gc.collect()

0 commit comments

Comments
 (0)