diff --git a/CHANGELOG.md b/CHANGELOG.md index 3239310763..ecbc5dd4b5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,7 +12,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - Fixed a crash in `TextArea` when undoing an edit to a selection the selection was made backwards https://github.com/Textualize/textual/issues/4301 - Fixed issue with flickering scrollbars https://github.com/Textualize/textual/pull/4315 - Fix progress bar ETA not updating when setting `total` reactive https://github.com/Textualize/textual/pull/4316 -- Exceptions inside `Widget.compose` weren't bubbling up in tests https://github.com/Textualize/textual/issues/4282 +- Exceptions inside `Widget.compose` or workers weren't bubbling up in tests https://github.com/Textualize/textual/issues/4282 ### Changed diff --git a/src/textual/worker.py b/src/textual/worker.py index 7719cd4dca..6cef3f6b90 100644 --- a/src/textual/worker.py +++ b/src/textual/worker.py @@ -375,7 +375,7 @@ async def _run(self, app: App) -> None: app.log.worker(Traceback()) if self.exit_on_error: - app._fatal_error() + app._handle_exception(error) else: self.state = WorkerState.SUCCESS app.log.worker(self) diff --git a/tests/test_pilot.py b/tests/test_pilot.py index 10ea623453..4a95b9c0fc 100644 --- a/tests/test_pilot.py +++ b/tests/test_pilot.py @@ -2,7 +2,7 @@ import pytest -from textual import events +from textual import events, work from textual.app import App, ComposeResult from textual.binding import Binding from textual.containers import Center, Middle @@ -71,7 +71,7 @@ def compose(self) -> ComposeResult: pass -async def test_pilot_exception_cathing_widget_compose(): +async def test_pilot_exception_catching_widget_compose(): class SomeScreen(Screen[None]): def compose(self) -> ComposeResult: 1 / 0 @@ -101,6 +101,20 @@ def action_beep(self) -> None: await pilot.press("b") +async def test_pilot_exception_catching_worker(): + class SimpleAppThatCrashes(App[None]): + def on_mount(self) -> None: + self.crash() + + @work(name="crash") + async def crash(self) -> None: + 1 / 0 + + with pytest.raises(ZeroDivisionError): + async with SimpleAppThatCrashes().run_test(): + pass + + async def test_pilot_click_screen(): """Regression test for https://github.com/Textualize/textual/issues/3395.