diff --git a/tests/playwright/examples/test_examples.py b/tests/playwright/examples/test_examples.py index 6977f77c8..536f1416b 100644 --- a/tests/playwright/examples/test_examples.py +++ b/tests/playwright/examples/test_examples.py @@ -12,6 +12,7 @@ def test_examples(page: Page, ex_app_path: str) -> None: skip_on_windows_with_timezonefinder(ex_app_path) + skip_airmass_on_3_9(ex_app_path) validate_example(page, ex_app_path) @@ -33,3 +34,33 @@ def skip_on_windows_with_timezonefinder(ex_app_path: str) -> None: pytest.skip( "timezonefinder has difficulty compiling on windows. Skipping example app. posit-dev/py-shiny#1651" ) + + +def skip_airmass_on_3_9(ex_app_path: str) -> None: + print(ex_app_path) + if ex_app_path != "examples/airmass/app.py": + return + + import sys + + if sys.version_info[:2] != (3, 9): + return + + try: + # Astropy loads `numpy` at run time + import astropy.coordinates as _ # pyright: ignore # noqa: F401 + import astropy.units as __ # pyright: ignore # noqa: F401 + + # Future proofing: if astropy is _actually_ loading, raise an error + raise RuntimeError( + "This code believes astropy and numpy have difficulty loading on python 3.9. Please remove this check if it is no longer true." + ) + except AttributeError as e: + if "numpy" in str(e) and "product" in str(e): + pytest.skip( + "astropy and numpy has difficulty loading on python 3.9. Skipping example app: airmass. posit-dev/py-shiny#1678" + ) + return + + # Future proofing: if the error is not what we expect, raise it + raise e diff --git a/tests/playwright/shiny/components/data_frame/pandas_compatible/test_df_pandas_compatible.py b/tests/playwright/shiny/components/data_frame/pandas_compatible/test_df_pandas_compatible.py index 283a74aca..0978b5708 100644 --- a/tests/playwright/shiny/components/data_frame/pandas_compatible/test_df_pandas_compatible.py +++ b/tests/playwright/shiny/components/data_frame/pandas_compatible/test_df_pandas_compatible.py @@ -1,11 +1,16 @@ import re from playwright.sync_api import Page +from utils.deploy_utils import skip_on_python_version from shiny.playwright import controller from shiny.run import ShinyAppProc +@skip_on_python_version( + "3.9", + reason="Astropy (and numpy) hav difficulty loading on python 3.9. posit-dev/py-shiny#1678", +) def test_data_frame_pandas_compatible( page: Page, local_app: ShinyAppProc, diff --git a/tests/playwright/utils/deploy_utils.py b/tests/playwright/utils/deploy_utils.py index 4a0b9d512..7b1a237d6 100644 --- a/tests/playwright/utils/deploy_utils.py +++ b/tests/playwright/utils/deploy_utils.py @@ -9,7 +9,7 @@ import tempfile import time import warnings -from typing import Any, Callable, List, TypeVar +from typing import Any, Callable, List, Optional, TypeVar import pytest import requests @@ -68,6 +68,39 @@ def skip_on_webkit(fn: CallableT) -> CallableT: return fn +def skip_on_python_version( + version: str, + reason: Optional[str] = None, +) -> Callable[[CallableT], CallableT]: + + reason_str = reason or f"Do not run on python {version}" + + is_valid_version = ( + re.match(r"\d+", version) + or re.match(r"\d+\.\d+", version) + or re.match(r"\d+\.\d+\.\d+", version) + ) is not None + + assert is_valid_version + + def _(fn: CallableT) -> CallableT: + + versions_match = True + for i, v in enumerate(version.split(".")): + if sys.version_info[i] != int(v): + versions_match = False + break + + fn = pytest.mark.skipif( + versions_match, + reason=reason_str, + )(fn) + + return fn + + return _ + + def run_command(cmd: str) -> str: output = subprocess.run( cmd,