pytest.create_app_fixture
='module') pytest.create_app_fixture(app, scope
Create a fixture for a local Shiny app directory.
Creates a fixture for a local Shiny app that is not contained within the same folder. This fixture is used to start the Shiny app process and return the local URL of the app.
If the app path is located in the same directory as the test file, then create_app_fixture()
can be skipped and local_app
test fixture can be used instead.
Parameters
Name | Type | Description | Default |
---|---|---|---|
app | Union[PurePath, str] | The path to the Shiny app file. If app is a Path or PurePath instance and Path(app).is_file() returns True , then this value will be used directly. Note, app ’s file path will be checked from where corresponding pytest test is collected, not necessarily where create_app_fixture() is called. Otherwise, all app paths will be considered to be relative paths from where the test function was collected. To be sure that your app path is always relative, supply a str value. |
required |
scope | ScopeName | The scope of the fixture. | 'module' |
Returns
Name | Type | Description |
---|---|---|
fixture_func |
The fixture function. |
Examples
from playwright.sync_api import Page
from shiny.playwright import controller
from shiny.pytest import create_app_fixture
from shiny.run import ShinyAppProc
# The variable name `app` MUST match the parameter name in the test function
= create_app_fixture("relative/path/to/app.py")
app
def test_app_code(page: Page, app: ShinyAppProc):
page.goto(app.url)# Add test code here
...