Skip to content

test(CLI): Update test template to use create_app_fixture #2028

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 1 addition & 20 deletions shiny/_main_add_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,28 +73,10 @@ def path_does_not_exist(x: Path) -> bool | str:
if not test_file.name.startswith("test_"):
return "Test file must start with 'test_'"

# if app path directory is the same as the test file directory, use `local_app`
# otherwise, use `create_app_fixture`
is_same_dir = app_file.parent == test_file.parent

test_name = test_file.name.replace(".py", "")
rel_path = os.path.relpath(app_file, test_file.parent)

template = (
f"""\
from playwright.sync_api import Page

from shiny.playwright import controller
from shiny.run import ShinyAppProc


def {test_name}(page: Page, local_app: ShinyAppProc):

page.goto(local_app.url)
# Add test code here
"""
if is_same_dir
else f"""\
template = f"""\
from playwright.sync_api import Page

from shiny.playwright import controller
Expand All @@ -109,7 +91,6 @@ def {test_name}(page: Page, app: ShinyAppProc):
page.goto(app.url)
# Add test code here
"""
)
# Make sure test file directory exists
test_file.parent.mkdir(parents=True, exist_ok=True)

Expand Down
Loading