importwarningsimportasyncioasyncdefspam():
withwarnings.catch_warnings(record=True) asws:
awaitasyncio.sleep(0.1)
w=Warning("12345")
warnings.warn(w)
assertwin (ww.messageforwwinws)
asyncdefham():
withwarnings.catch_warnings(record=True) asws:
awaitasyncio.sleep(0.2)
asyncdefmain():
awaitasyncio.gather(spam(), ham())
asyncio.run(main())Despite technically being documented (https://docs.python.org/3/library/warnings.html#warnings.catch_warnings), this is very error-prone, surprising and not at all useful. The warnings module should probably use contextvars to manage the warning handler.
Despite technically being documented (https://docs.python.org/3/library/warnings.html#warnings.catch_warnings), this is very error-prone, surprising and not at all useful. The warnings module should probably use
contextvarsto manage the warning handler.