Python has the concept of *unraisable exceptions* - exceptions that cannot
be raised at the time they occur because they would break something about
the runtime. For example, an exception raised during an object's __del__
method would break garbage collection.
Python 3.8 added the ability to take action when unraisable exceptions
occur, by setting sys.unraisablehook to a callable (
https://docs.python.org/3.8/library/sys.html#sys.unraisablehook ). I
propose that we extend Django's test runner to add such a hook that records
if any unraisable exceptions occur during a test run, and fails the test
run if this is the case.

The use case I came across for this was using asyncio in debug mode, which
warns about unawaited coroutines and unretrieved futures (
https://docs.python.org/3.8/library/asyncio-dev.html#detect-never-awaited-coroutines
). It can be very handy to add a warning filter to turn these RuntimeWarnings
into exceptions in tests and development. Unfortunately such exceptions are
always (or often?) *unraisable*, so Python prints their stack trace with
the default unraisable hook, but carries on as if no error occurred.
Failing test runs if unraisable exceptions occur could help highlight such
issues.

I'm writing to the mailing list because I'm not sure if failing the test
run would *always* make sense. Does anyone else have experience with
unraisable exceptions?

FWIW, pytest has only one stalled discussion:
https://github.com/pytest-dev/pytest/issues/5299
-- 
Adam

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/CAMyDDM3nN-D3hLhjbWt%2BqGt0xqhho1GVdTrOEdfx2GJ17JVb7Q%40mail.gmail.com.
  • Fai... Adam Johnson
    • ... Carlton Gibson
      • ... Adam Johnson
        • ... Carlton Gibson
          • ... Adam Johnson
            • ... Carlton Gibson
              • ... Adam Johnson
                • ... Tom Forbes
                • ... Carlton Gibson
                • ... 'Adam Johnson' via Django developers (Contributions to Django itself)

Reply via email to