`run_test()` doesn't install the eager task factory, so tasks start in a different order than under `run()`
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 22/100
Línea de trabajo
Compare how run_async() installs asyncio.eager_task_factory with how run_test() starts the app in the Textual app module, then reproduce the ordering script from the issue. Done means run_test() matches run() and the three failing tests in tests/command_palette/test_declare_sources.py pass. Those tests depend on the screen-startup behaviour tracked in #6444, so that needs settling first, and a maintainer should confirm the direction before you start.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Hi! I hit this while comparing an app's behaviour under run() with the same app under run_test(). Since #6102, run_async() sets asyncio.eager_task_factory on the loop (Python 3.12+), but run_test() doesn't, so a task created in a handler starts at a different point depending on how the app is run. #6492 mentions this too.
import asyncio
import sys
import textual
from textual.app import App
class OrderApp(App[list]):
def on_mount(self) -> None:
self.order = []
async def task() -> None:
self.order.append("task started")
asyncio.create_task(task())
self.order.append("on_mount continued")
self.set_timer(0.1, lambda: self.exit(self.order))
async def under_run_test() -> list:
app = OrderApp()
async with app.run_test() as pilot:
await pilot.pause(0.2)
return app.order
print(f"Textual {textual.__version__}, Python {sys.version.split()[0]}")
print("run(): ", OrderApp().run(headless=True))
print("run_test():", asyncio.run(under_run_test()))
Output on Textual 8.2.7 and on main (5e5b7ef), Python 3.13:
Textual 8.2.7, Python 3.13.18
run(): ['task started', 'on_mount continued']
run_test(): ['on_mount continued', 'task started']
So a test can pass while the real app behaves differently, or the other way round. #6444 is one example: it crashes under run() but not under run_test().
The obvious fix is to set the same factory in run_test() (and restore the previous one on exit). I tried that on main and it's not quite enough on its own:
- The order above then matches
run(). - Three tests in
tests/command_palette/test_declare_sources.pyfail (test_no_screen_command_sources,test_screen_command_sources,test_app_and_screen_command_sources_combine). They push a screen inon_mountwhose ownon_mountopens the command palette. With the eager factory,run_test()gives a screen stack of['Screen', 'CommandPalette', 'PaletteOnMount'], so the palette ends up under the screen that opened it. Underrun()the same app gives['Screen', 'PaletteOnMount', 'CommandPalette']. I think that's the same problem as #6444 (a screen's children start before the screen is on the stack), so there may be a startup difference between the two paths beyond the task factory. - The rest of the suite is unchanged.
Is run_test() meant to match run() here? If so, I'm happy to open a PR that sets the factory, but the three tests above would need #6444 (or a change to how run_test() starts the app) first, so I wanted to check which way you'd prefer.
- Lenguaje dominante
- Python
- Estrellas
- 37.7k
- Forks
- 1.5k
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de Textualize/textual
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Textualize/textual#6790 · 2 comentarios ·
-
Markdown table of contents: the node added for a skipped heading level shows the wrong numeralAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 80/100
Textualize/textual#6789 · 1 comentario ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Textualize/textual#6787 · 1 comentario ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Textualize/textual#6782 · 1 comentario ·
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 85/100
Textualize/textual#6778 · 1 comentario ·
Todos los issues de Textualize/textual
Issues similares
-
Internal ErrorAbiertobug
Dificultad 2/5 1-3 horas Aptitud para principiantes 66/100
frappe/frappe_docker#2071 ·
Los mantenedores suelen responder en 1 día
-
bug python
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
traceloop/openllmetry#4717 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
The-Pocket/PocketFlow#161 ·
-
[Bug]: Webapp workspace fails to render in Safari — "Can't find variable: requestIdleCallback"Abiertocomp/desktop P2 type/bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
NousResearch/hermes-agent#157702 ·
Los mantenedores suelen responder en 1 día
-
scibench_physics / scibench_chemistry: a correct answer scores 0 when the unit has a power of tenPosiblemente ocupada @BahaaMattar la tomó hoy. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
EvolvingLMMs-Lab/lmms-eval#1699 ·
Los mantenedores suelen responder en 1 día