Fix tests.

This commit is contained in:
Rodrigo Girão Serrão
2024-03-26 10:56:36 +00:00
parent 8c48a3b95d
commit 809f38341f
3 changed files with 14 additions and 11 deletions

View File

@@ -375,7 +375,8 @@ class Worker(Generic[ResultType]):
app.log.worker(Traceback())
if self.exit_on_error:
app._handle_exception(error)
worker_failed = WorkerFailed(self._error)
app._handle_exception(worker_failed)
else:
self.state = WorkerState.SUCCESS
app.log.worker(self)

View File

@@ -9,6 +9,7 @@ from textual.containers import Center, Middle
from textual.pilot import OutOfBounds
from textual.screen import Screen
from textual.widgets import Button, Label
from textual.worker import WorkerFailed
KEY_CHARACTERS_TO_TEST = "akTW03" + punctuation
"""Test some "simple" characters (letters + digits) and all punctuation."""
@@ -110,9 +111,10 @@ async def test_pilot_exception_catching_worker():
async def crash(self) -> None:
1 / 0
with pytest.raises(ZeroDivisionError):
with pytest.raises(WorkerFailed) as exc:
async with SimpleAppThatCrashes().run_test():
pass
assert exc.type is ZeroDivisionError
async def test_pilot_click_screen():

View File

@@ -113,10 +113,10 @@ async def test_run_error() -> None:
pass
app = ErrorApp()
async with app.run_test():
worker: Worker[str] = Worker(app, run_error)
worker._start(app)
with pytest.raises(WorkerFailed):
with pytest.raises(WorkerFailed):
async with app.run_test():
worker: Worker[str] = Worker(app, run_error)
worker._start(app)
await worker.wait()
@@ -218,12 +218,12 @@ async def test_self_referential_deadlock():
await get_current_worker().wait()
app = App()
async with app.run_test():
worker = Worker(app, self_referential_work)
worker._start(app)
with pytest.raises(WorkerFailed) as exc:
with pytest.raises(WorkerFailed) as exc:
async with app.run_test():
worker = Worker(app, self_referential_work)
worker._start(app)
await worker.wait()
assert exc.type is DeadlockError
assert exc.type is DeadlockError
async def test_wait_without_start():