Skip to content

test(py): drive servers with shiny's local_server fixture - #305

Merged
schloerke merged 1 commit into
mainfrom
schloerke/test-server-local-server-fixture
Sep 12, 2026
Merged

schloerke merged 1 commit into
mainfrom
schloerke/test-server-local-server-fixture

Conversation

@schloerke

Copy link
Copy Markdown
Collaborator

py-shiny main ships a built-in local_server pytest fixture — an already-started test_server() session — so a test needs neither the with block nor its own APP = Path(...) constant.

What changed

Every Python test_server() call site now uses the fixture: pkg-py/tests/test_in_memory_server.py and the seven example suites (01, 02, 05, 06, 07, 08, 10).

The fixture defaults to app.py beside the test file; ours live in tests/, so each file carries a one-line mark pointing it a directory up:

pytestmark = pytest.mark.parametrize("local_server", ["../app.py"], indirect=True)

01-hello uses the same mark to cover both ../app.py and ../app-core.py, replacing its hand-rolled APPS parametrize. test_in_memory_server.py uses per-test marks instead, since its apps are the Playwright fixture apps under playwright/apps/.

Two py-shiny API changes surfaced

Docs

shinyreact-build-app's references/testing.md + SKILL.md, shinyreact-convert-app/SKILL.md, examples/README.md, pkg-py/README.md, pkg-py/docs/articles/testing.qmd, and three examples/*/FEATURES.md leaves. make update-skills run for the shipped copies.

Verification

  • make py-check — ruff clean, pyright 0 errors, 197 passed
  • make py-test-e2e (chromium) — 28 passed
  • devtools::test() in pkg-r — 323 passed, 0 failures

py-shiny main ships a built-in `local_server` pytest fixture -- an
already-started `test_server()` session -- so a test needs neither the
`with` block nor its own `APP = Path(...)` constant. Switch every Python
call site to it: the fixture defaults to `app.py` beside the test file,
and ours live in `tests/`, so each file carries a one-line
`pytestmark` pointing it a directory up. `01-hello` uses the same mark to
cover both `../app.py` and `../app-core.py`, replacing its hand-rolled
`APPS` parametrize.

Two API changes on py-shiny main surfaced in the process:

- `make_scope()` is no longer a context manager.
- A `req()` failure now reports `status == "silent"` rather than leaving
  the previous value in place (posit-dev/py-shiny#2492).
  `test_output_error_statuses` asserted the old behavior. R's
  `test-render.R` called this out as a deliberate R/Python divergence in
  a comment; it is not one anymore.

Docs and both shipped skills updated to teach the fixture.
@schloerke
schloerke enabled auto-merge (squash) September 12, 2026 21:55
@schloerke
schloerke merged commit e9fe448 into main Sep 12, 2026
18 checks passed
@schloerke
schloerke deleted the schloerke/test-server-local-server-fixture branch September 12, 2026 22:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant