#32557: Fail tests when unraisable exceptions occur
-----------------------------------+--------------------------------------
Reporter: Adam Johnson | Owner: nobody
Type: New feature | Status: new
Component: Testing framework | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------------+--------------------------------------
Comment (by Adam Johnson):
There's a reference implementation in pytest we might be able to copy:
https://github.com/pytest-dev/pytest/pull/8055
Additionally here's an implementation I've used - calling the context
manager in an overridden DiscoverRunner.run_tests to wrap the whole test
run:
{{{
@contextmanager
def fail_if_any_unraisable_exceptions():
orig_unraisable_hook = sys.unraisablehook
hook_called = multiprocessing.Value("b", lock=False)
hook_called.value = 0
def hook(unraisable, /):
hook_called.value = 1
orig_unraisable_hook(unraisable)
sys.unraisablehook = hook
try:
yield
finally:
sys.unraisablehook = orig_unraisable_hook
if hook_called.value:
print(
"❌ Unraisable exceptions reported, failing test run - see
above.",
file=sys.stderr,
)
sys.exit(1)
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/32557#comment:1>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/068.d33e52e278437918f02a03e46ea193a1%40djangoproject.com.