diff --git a/src/dbxs/_testing.py b/src/dbxs/_testing.py index f277143..8bf7dd8 100644 --- a/src/dbxs/_testing.py +++ b/src/dbxs/_testing.py @@ -146,24 +146,19 @@ def schedule( @dataclass class DeferredCompletionTester: failer: Callable[[str], None] - deferred: Deferred[object] + succeeded: list[object] + failed: list[Failure] def assertNoResult(self) -> None: - succeeded: list[object] = [] - failed: list[Failure] = [] - self.deferred.addCallbacks(succeeded.append, failed.append) - if failed: - failed[0].raiseException() - if succeeded: - self.failer(f"unexpected result {succeeded[0]}") + if self.failed: + self.failed[0].raiseException() + if self.succeeded: + self.failer(f"unexpected result {self.succeeded[0]}") def assertSuccessResult(self) -> None: - succeeded: list[object] = [] - failed: list[Failure] = [] - self.deferred.addCallbacks(succeeded.append, failed.append) - if failed: - failed[0].raiseException() - if not succeeded: + if self.failed: + self.failed[0].raiseException() + if not self.succeeded: self.failer("no result") @@ -173,10 +168,11 @@ def schedule( failer: Callable[[str], None], coroutine: Coroutine[Any, Any, Any], ) -> CompletionTester: - return DeferredCompletionTester( - failer, - Deferred.fromCoroutine(coroutine), - ) + succeeded: list[object] = [] + failed: list[Failure] = [] + deferred = Deferred.fromCoroutine(coroutine) + deferred.addCallbacks(succeeded.append, failed.append) + return DeferredCompletionTester(failer, succeeded, failed) def immediateTest( diff --git a/src/dbxs/test/test_testing.py b/src/dbxs/test/test_testing.py index d199dd9..983c1cd 100644 --- a/src/dbxs/test/test_testing.py +++ b/src/dbxs/test/test_testing.py @@ -38,7 +38,7 @@ async def method(self: TestFailing, pool: MemoryPool) -> None: def test_failsBeforeBlocking(self) -> None: """ - If an @immediateTest raises an exception, taht exception is re-raised. + If an @immediateTest raises an exception, that exception is re-raised. """ @immediateTest() @@ -47,3 +47,17 @@ async def method(self: TestFailing, pool: MemoryPool) -> None: with self.assertRaises(ZeroDivisionError): method(self) + + def test_failsAfterBlocking(self) -> None: + """ + If an @immediateTest raises an exception after blocking, that exception + is re-raised as well. + """ + + @immediateTest() + async def method(self: TestFailing, pool: MemoryPool) -> None: + await pool.connectable.connect() + 1 / 0 + + with self.assertRaises(ZeroDivisionError): + method(self)