Skip to content

Commit 5faf62b

Browse files
authored
test: Update test to use variable, not capture stdout (#1236)
1 parent b7816b7 commit 5faf62b

File tree

2 files changed

+19
-39
lines changed

2 files changed

+19
-39
lines changed

tests/playwright/shiny/session/flush/app.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import annotations
22

33
import asyncio
4+
from typing import List
45

56
from shiny import App, Inputs, Outputs, Session, reactive, render, ui
67

@@ -37,8 +38,10 @@
3738
ui.output_text_verbatim("all_txt", placeholder=True),
3839
ui.tags.span("Flush events: "),
3940
ui.output_text_verbatim("flush_txt", placeholder=True),
40-
ui.tags.span("Flushed: "),
41+
ui.tags.span("Flushed events: "),
4142
ui.output_text_verbatim("flushed_txt", placeholder=True),
43+
ui.tags.span("Session end events (refresh App to add events): "),
44+
ui.output_text_verbatim("session_end_txt", placeholder=True),
4245
ui.tags.script(
4346
"""
4447
$(document).on('shiny:connected', function(event) {
@@ -55,18 +58,20 @@
5558
),
5659
)
5760

61+
session_ended_messages: List[str] = []
62+
5863

5964
def server(input: Inputs, output: Outputs, session: Session):
6065
def on_ended_sync(txt: str):
6166
def _():
62-
print(txt)
67+
session_ended_messages.append(txt)
6368

6469
return _
6570

6671
def on_ended_async(txt: str):
6772
async def _():
6873
await asyncio.sleep(0)
69-
print(txt)
74+
session_ended_messages.append(txt)
7075

7176
return _
7277

@@ -181,5 +186,9 @@ def flush_txt():
181186
def flushed_txt():
182187
return str(flushed_vals.get())
183188

189+
@render.text
190+
def session_end_txt():
191+
return str(session_ended_messages)
192+
184193

185194
app = App(app_ui, server)
Lines changed: 7 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,10 @@
1-
import os
2-
3-
import pytest
41
from conftest import ShinyAppProc
52
from controls import OutputTextVerbatim
63
from playwright.sync_api import Page
74

8-
on_ci = os.environ.get("CI", "False") == "true"
9-
105

116
def test_output_image_kitchen(page: Page, local_app: ShinyAppProc) -> None:
127

13-
if on_ci:
14-
# 2024-03-22: The tests pass locally, but do not pass on CI. It started with
15-
# https://github.com/posit-dev/py-shiny/commit/2f75a9076c567690f2a6a647ec07cfa9e558ff9c
16-
# , but the changes in that commit were unrelated. We had believe it was an
17-
# update in uvicorn, but removing all other debug statements did not fix the
18-
# issue.
19-
# 2024-03-22 Barret: When inspecting the issue, we found that many log
20-
# INFO entries have different port values. This is concerning.
21-
# https://github.com/posit-dev/py-shiny/pull/1236
22-
pytest.skip("Error with stdout / stderr on CI. Related #1236")
23-
248
page.goto(local_app.url)
259

2610
OutputTextVerbatim(page, "all_txt").expect_value(
@@ -37,23 +21,10 @@ def test_output_image_kitchen(page: Page, local_app: ShinyAppProc) -> None:
3721
"('a-3-flushed', 'bx-3-first-flushed', 'by-3-first-flushed', "
3822
"'bx-3-second-flushed', 'by-3-second-flushed', 'c-3-flushed')"
3923
)
40-
41-
# Verify `on_ended` callbacks are called in the correct order (and cancelled)
42-
local_app.close()
43-
44-
# Wait up to 3 seconds for the app to close and print the logs. (Should be ~ instant)
45-
local_app.stdout.wait_for(lambda x: "test4" in x, 3)
46-
stdout = str(local_app.stdout)
47-
out_indexes = [
48-
stdout.index("session ended - sync - test1"),
49-
stdout.index("session ended - async - test2"),
50-
stdout.index("session ended - async - test3"),
51-
stdout.index("session ended - sync - test4"),
52-
]
53-
for i in range(len(out_indexes)):
54-
index = out_indexes[i]
55-
assert index >= 0
56-
# Make sure they are ordered correctly
57-
if i > 0:
58-
prev_index = out_indexes[i - 1]
59-
assert index > prev_index
24+
# Session end messages have not flushed yet
25+
OutputTextVerbatim(page, "session_end_txt").expect_value("[]")
26+
page.reload()
27+
# Session end messages have flushed
28+
OutputTextVerbatim(page, "session_end_txt").expect_value(
29+
"['session ended - sync - test1', 'session ended - async - test2', 'session ended - async - test3', 'session ended - sync - test4']"
30+
)

0 commit comments

Comments
 (0)