Replies: 2 comments 1 reply
-
I probably should have mentioned, that my workaround for now is somewhat long and ugly: import threading
import sys
import pytest
class SysExitThread(threading.Thread):
"""Pass exception from thread run to the parent"""
def __init__(self, group=None, target=None, name=None, args=(), kwargs=None, *, daemon=None):
super().__init__(group=group, target=target, name=name, args=args, kwargs=kwargs, daemon=daemon)
self._exc = None
def run(self):
try:
super().run()
except SystemExit as exc:
self._exc = exc
def join(self, timeout=None):
super().join(timeout=timeout)
if self._exc:
raise self._exc
def test_sys_exit():
def foo():
sys.exit(42)
t = SysExitThread(target=foo)
t.start()
with pytest.raises(SystemExit) as exc:
t.join()
assert exc.typename == "SystemExit" |
Beta Was this translation helpful? Give feedback.
0 replies
-
Pytest intentionally warns about this as threads that fail with exception indicate gruesome failure |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hello,
I have a test, which results in
sys.exit
call. Something similar to following code:Recently pytest started warning about unhandled
SystemExit
exception. I made several attempts to resolve this warning, and was unable to. What would be a correct way to handle this case? I know, I can disable a plugin, but I'm pretty sure there should be a way to handle it properly, but I'm not seeing it... yet.Thanks.
Beta Was this translation helpful? Give feedback.
All reactions