From ef7a5855703f3cc881f462377f6e566fce6debf9 Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Mon, 10 Mar 2025 18:17:31 -0400 Subject: [PATCH] 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:`. --- tractor/_testing/__init__.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/tractor/_testing/__init__.py b/tractor/_testing/__init__.py index 43507c33..88860d13 100644 --- a/tractor/_testing/__init__.py +++ b/tractor/_testing/__init__.py @@ -26,6 +26,9 @@ import os import pathlib import tractor +from tractor.devx._debug import ( + BoxedMaybeException, +) from .pytest import ( tractor_test as tractor_test ) @@ -98,12 +101,13 @@ async def expect_ctxc( ''' if yay: try: - yield + yield (maybe_exc := BoxedMaybeException()) raise RuntimeError('Never raised ctxc?') - except tractor.ContextCancelled: + except tractor.ContextCancelled as ctxc: + maybe_exc.value = ctxc if reraise: raise else: return else: - yield + yield (maybe_exc := BoxedMaybeException())