Skip to content

Commit

Permalink
Surface exceptions from workers to testing frameworks.
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigogiraoserrao committed Mar 25, 2024
1 parent 74ab967 commit 8c48a3b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/textual/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
18 changes: 16 additions & 2 deletions tests/test_pilot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 8c48a3b

Please sign in to comment.