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 | PurePath | str | list [PurePath | str] |
The path (or a list of paths) 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. If app is a list of path values, then the fixture will be parametrized and each test will be run for each path in the list. |
required |
scope | ScopeName | The scope of the fixture. The default is module , which means that the fixture will be created once per module. See Pytest fixture scopes for more details. |
'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
...
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
# The tests below will run for each path provided
= create_app_fixture(["relative/path/to/first/app.py", "relative/path/to/second/app.py"])
app
def test_app_code(page: Page, app: ShinyAppProc):
page.goto(app.url)# Add test code here
...
def test_more_app_code(page: Page, app: ShinyAppProc):
page.goto(app.url)# Add test code here
...