Deliver a `MaybeBoxedError` from `.expect_ctxc()`

Just like we do from the `.devx._debug.open_crash_handler()`, this
allows checking various attrs on the raised `ContextCancelled` much like
`with pytest.raises() as excinfo:`.
Tyler Goodlet 2025-03-10 18:17:31 -04:00
parent 4d9f6e733a
commit ef7a585570
1 changed files with 7 additions and 3 deletions

View File

@ -26,6 +26,9 @@ import os
import pathlib import pathlib
import tractor import tractor
from tractor.devx._debug import (
BoxedMaybeException,
)
from .pytest import ( from .pytest import (
tractor_test as tractor_test tractor_test as tractor_test
) )
@ -98,12 +101,13 @@ async def expect_ctxc(
''' '''
if yay: if yay:
try: try:
yield yield (maybe_exc := BoxedMaybeException())
raise RuntimeError('Never raised ctxc?') raise RuntimeError('Never raised ctxc?')
except tractor.ContextCancelled: except tractor.ContextCancelled as ctxc:
maybe_exc.value = ctxc
if reraise: if reraise:
raise raise
else: else:
return return
else: else:
yield yield (maybe_exc := BoxedMaybeException())