test(py): drive servers with shiny's local_server fixture - #305
Merged
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
py-shiny main ships a built-in
local_serverpytest fixture — an already-startedtest_server()session — so a test needs neither thewithblock nor its ownAPP = Path(...)constant.What changed
Every Python
test_server()call site now uses the fixture:pkg-py/tests/test_in_memory_server.pyand the seven example suites (01,02,05,06,07,08,10).The fixture defaults to
app.pybeside the test file; ours live intests/, so each file carries a one-line mark pointing it a directory up:01-hellouses the same mark to cover both../app.pyand../app-core.py, replacing its hand-rolledAPPSparametrize.test_in_memory_server.pyuses per-test marks instead, since its apps are the Playwright fixture apps underplaywright/apps/.Two py-shiny API changes surfaced
make_scope()is no longer a context manager —a = local_server.make_scope("a").req()failure now reportsstatus == "silent"rather than leaving the previous value in place (test_server(): a silent req() failure is invisible — get_output() keeps the stale value while the browser blanks the output py-shiny#2492).test_output_error_statusesasserted the old behavior; it now asserts the blank, matching what the browser shows.pkg-r/tests/testthat/test-render.Rcalled this out as a deliberate R/Python divergence in a comment — it is not one anymore, so the comment is updated.Docs
shinyreact-build-app'sreferences/testing.md+SKILL.md,shinyreact-convert-app/SKILL.md,examples/README.md,pkg-py/README.md,pkg-py/docs/articles/testing.qmd, and threeexamples/*/FEATURES.mdleaves.make update-skillsrun for the shipped copies.Verification
make py-check— ruff clean, pyright 0 errors, 197 passedmake py-test-e2e(chromium) — 28 passeddevtools::test()inpkg-r— 323 passed, 0 failures