From 53cf486ac8d0fa96d1ef6be6b97dff3673624117 Mon Sep 17 00:00:00 2001 From: Karan Gathani Date: Sun, 13 Jul 2025 07:15:48 +0530 Subject: [PATCH 1/3] Update test template to use create_app_fixture Replaces the use of 'local_app' with 'app' and utilizes 'create_app_fixture' from shiny.pytest for test setup. This improves consistency and aligns with updated testing practices. --- shiny/_main_add_test.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/shiny/_main_add_test.py b/shiny/_main_add_test.py index ac4c4f785..f8886bb7c 100644 --- a/shiny/_main_add_test.py +++ b/shiny/_main_add_test.py @@ -85,12 +85,15 @@ def path_does_not_exist(x: Path) -> bool | str: from playwright.sync_api import Page from shiny.playwright import controller +from shiny.pytest import create_app_fixture from shiny.run import ShinyAppProc +app = create_app_fixture("{app_file.name}") + -def {test_name}(page: Page, local_app: ShinyAppProc): +def {test_name}(page: Page, app: ShinyAppProc): - page.goto(local_app.url) + page.goto(app.url) # Add test code here """ if is_same_dir From 5cadc93e70b712e7f8be641762ed278be3f3636e Mon Sep 17 00:00:00 2001 From: Karan Gathani Date: Sun, 13 Jul 2025 13:46:22 +0530 Subject: [PATCH 2/3] Remove duplicate app fixture and test template code Eliminated redundant app fixture and test function template from shiny/_main_add_test.py, streamlining the code and preventing duplication. --- shiny/_main_add_test.py | 20 +------------------- 1 file changed, 1 insertion(+), 19 deletions(-) diff --git a/shiny/_main_add_test.py b/shiny/_main_add_test.py index f8886bb7c..fdc2bf57d 100644 --- a/shiny/_main_add_test.py +++ b/shiny/_main_add_test.py @@ -80,24 +80,7 @@ def path_does_not_exist(x: Path) -> bool | str: 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.pytest import create_app_fixture -from shiny.run import ShinyAppProc - -app = create_app_fixture("{app_file.name}") - - -def {test_name}(page: Page, app: ShinyAppProc): - - page.goto(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 @@ -112,7 +95,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) From d9d3a09a1700ebea53baaf186c1f61e885b23d06 Mon Sep 17 00:00:00 2001 From: Karan Gathani Date: Sun, 13 Jul 2025 14:14:54 +0530 Subject: [PATCH 3/3] Remove unused is_same_dir variable in add_test_file Deleted the is_same_dir variable and related comments from add_test_file as it was not used in the function. --- shiny/_main_add_test.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/shiny/_main_add_test.py b/shiny/_main_add_test.py index fdc2bf57d..7393054d0 100644 --- a/shiny/_main_add_test.py +++ b/shiny/_main_add_test.py @@ -73,10 +73,6 @@ 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)