-
Consider such a test: def test_select() -> None:
# ARRANGE
expected_value: Final[int] = 1
# ACT
select = Select(options=[(str(expected_value), expected_value)], value=expected_value)
# ASSERT
assert select.value == expected_value it is failing because: # ASSERT
> assert select.value == expected_value
E assert None == 1
E + where None = Select().value |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Like a few things within Textual, the from textual.app import App, ComposeResult
from textual.widgets import Select
class SelectApp(App[None]):
INITIAL_VALUE = 3
def compose(self) -> ComposeResult:
yield Select[int]([(str(n), n) for n in range(10)], value=self.INITIAL_VALUE)
async def test_select_initial_value():
async with SelectApp().run_test() as pilot:
assert pilot.app.query_one(Select).value == SelectApp.INITIAL_VALUE |
Beta Was this translation helpful? Give feedback.
-
This originates from the fact I have a thin wrapper around Select - If there is just a single option, there is nothing to select from, so just a |
Beta Was this translation helpful? Give feedback.
Like a few things within Textual, the
value
of theSelect
will only settle on a correct value once a DOM is available and the widget is fully mounted. It would be normal to test the working of the various widgets usingApp.run_test
. For example: