pytest.create_app_fixture
pytest.create_app_fixture(app, scope='module')
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
app: Union[PurePath, str]
-
The path to the Shiny app file.
If
app
is aPath
orPurePath
instance andPath(app).is_file()
returnsTrue
, then this value will be used directly. Note,app
’s file path will be checked from where correspondingpytest
test is collected, not necessarily wherecreate_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 astr
value. scope: ScopeName = ‘module’
-
The scope of the fixture.
Returns
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
...