Files
textual/tests/tree/test_tree_get_node_by_id.py
TomJGooding 7a9d32fdbf test: make tests async to fix failures on Python 3.9
After upgrading `pytest-asyncio` to the latest version, lots of tests
started failing in CI only on Python 3.9:

`RuntimeError: There is no current event loop in thread 'MainThread'`

Apparently these tests may have only been passing previously due to
issues in earlier versions of `pytest-asyncio`. Changing these tests to
async seems to fix the failures on Python 3.9.

Related issue:
https://github.com/pytest-dev/pytest-asyncio/issues/1039
2025-09-17 13:38:05 +01:00

19 lines
626 B
Python

from typing import cast
import pytest
from textual.widgets import Tree
from textual.widgets.tree import NodeID, UnknownNodeID
async def test_get_tree_node_by_id() -> None:
"""It should be possible to get a TreeNode by its ID."""
tree = Tree[None]("Anakin")
child = tree.root.add("Leia")
grandchild = child.add("Ben")
assert tree.get_node_by_id(tree.root.id).id == tree.root.id
assert tree.get_node_by_id(child.id).id == child.id
assert tree.get_node_by_id(grandchild.id).id == grandchild.id
with pytest.raises(UnknownNodeID):
tree.get_node_by_id(cast(NodeID, grandchild.id + 1000))