You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi!
Right now, it's very hard to test the shiny part of your dashboard.
While the internals of py-shiny are tested with playwright, the testing API with ShinyAppProc and more is not in the package.
I'm keeping my fingers crossed for a quick release of shiny.testing namespace as it would allow us creating testable (i.e. enterprise ready) shiny apps in python, just like in R. :)
Any ideas when to expect this feature?
Correct me if I'm wrong, but there's no issue on GH that tracks the progress of testing namespace, hence I created this one.
@karangattu and I are aiming for a testing release near conf in the early fall. We are hoping to have the existing classes (and their methods) documented and moved under shiny.test (or something similar).
It seems reasonable to try to make basic testing possible in the near future (knowing the API might change), such as the simple UI test linked above. (Functions related to conftest)
The other helper controls could be aded piecemeal as we document / vet them.
Great to hear that!
In the meantime, I'm working on the blog post on how to test pyshiny apps with playwright right now, will share here and on discord once it's ready :)
For adding tests to the CI/CD pipeline you can use this snippet in conftest.py (check this SO thread).
This assumes the app is defined as app = App(...) in the app.py file.
importthreadingimportpytestimportrequestsfromtenacityimportretry, stop_after_delay, wait_fixedfromuvicornimportConfig, ServerAPP_HOST="127.0.0.1"APP_PORT=8989APP_URL=f"http://{APP_HOST}:{APP_PORT}"@retry(wait=wait_fixed(0.5), stop=stop_after_delay(10))defwait_for_server_to_start(url):
response=requests.get(url) # noqa: S113response.raise_for_status() # Will raise an exception if the request is unsuccessful, i.e. server is not readydefrun_server():
config=Config(app="app:app", host=APP_HOST, port=APP_PORT, log_level="info")
server=Server(config)
server.run()
@pytest.fixture(scope="session", autouse=True)def_shiny_server():
# Start the server in a background threadthread=threading.Thread(target=run_server, daemon=True)
thread.start()
wait_for_server_to_start(APP_URL)
return
Activity
schloerke commentedon Apr 3, 2024
Hi @pstorozenko 👋 !
@karangattu and I are aiming for a testing release near conf in the early fall. We are hoping to have the existing classes (and their methods) documented and moved under
shiny.test(or something similar).It seems reasonable to try to make basic testing possible in the near future (knowing the API might change), such as the simple UI test linked above. (Functions related to
conftest)The other helper
controlscould be aded piecemeal as we document / vet them.pstorozenko commentedon Apr 3, 2024
Great to hear that!
In the meantime, I'm working on the blog post on how to test pyshiny apps with playwright right now, will share here and on discord once it's ready :)
pstorozenko commentedon Apr 11, 2024
For all those wanting to test your apps right now
It's great that there's an Epic for testing shiny apps 🎉
In the meantime you can check this repo with examples.
And the accompanying blog post.
For adding tests to the CI/CD pipeline you can use this snippet in
conftest.py(check this SO thread).This assumes the app is defined as
app = App(...)in theapp.pyfile.