diff --git a/pytest-playwright-asyncio/pytest_playwright_asyncio/pytest_playwright.py b/pytest-playwright-asyncio/pytest_playwright_asyncio/pytest_playwright.py index f1ebce0..e3c3981 100644 --- a/pytest-playwright-asyncio/pytest_playwright_asyncio/pytest_playwright.py +++ b/pytest-playwright-asyncio/pytest_playwright_asyncio/pytest_playwright.py @@ -831,7 +831,8 @@ def _is_pytest_base_url_loaded(pluginmanager: pytest.PytestPluginManager) -> boo class _BaseUrlFallback: # Provides the base_url fixture when pytest-base-url is not in use. @pytest.fixture(scope="session") - def base_url(self, pytestconfig: Any) -> Optional[str]: + @classmethod + def base_url(cls, pytestconfig: Any) -> Optional[str]: return ( pytestconfig.getoption("--base-url") or pytestconfig.getini("base_url") diff --git a/pytest-playwright/pytest_playwright/pytest_playwright.py b/pytest-playwright/pytest_playwright/pytest_playwright.py index fce034a..70676a3 100644 --- a/pytest-playwright/pytest_playwright/pytest_playwright.py +++ b/pytest-playwright/pytest_playwright/pytest_playwright.py @@ -828,7 +828,8 @@ def _is_pytest_base_url_loaded(pluginmanager: pytest.PytestPluginManager) -> boo class _BaseUrlFallback: # Provides the base_url fixture when pytest-base-url is not in use. @pytest.fixture(scope="session") - def base_url(self, pytestconfig: Any) -> Optional[str]: + @classmethod + def base_url(cls, pytestconfig: Any) -> Optional[str]: return ( pytestconfig.getoption("--base-url") or pytestconfig.getini("base_url") diff --git a/tests/test_asyncio.py b/tests/test_asyncio.py index d34e3ea..dcdd948 100644 --- a/tests/test_asyncio.py +++ b/tests/test_asyncio.py @@ -482,6 +482,27 @@ async def test_base_url(page, base_url): result.assert_outcomes(passed=1) +def test_base_url_without_pytest_base_url_does_not_warn( + testdir: pytest.Testdir, +) -> None: + # https://github.com/microsoft/playwright-pytest/issues/341 + testdir.makepyfile( + """ + def test_base_url(base_url): + assert base_url == "http://localhost" + """ + ) + result = testdir.runpytest( + "-p", + "no:base_url", + "--base-url", + "http://localhost", + "-W", + "error::pytest.PytestDeprecationWarning", + ) + result.assert_outcomes(passed=1) + + def test_base_url_without_plugin_autoload( testdir: pytest.Testdir, test_server: HTTPTestServer, diff --git a/tests/test_sync.py b/tests/test_sync.py index 9528fc5..195f210 100644 --- a/tests/test_sync.py +++ b/tests/test_sync.py @@ -495,6 +495,27 @@ def test_base_url(page, base_url): result.assert_outcomes(passed=1) +def test_base_url_without_pytest_base_url_does_not_warn( + testdir: pytest.Testdir, +) -> None: + # https://github.com/microsoft/playwright-pytest/issues/341 + testdir.makepyfile( + """ + def test_base_url(base_url): + assert base_url == "http://localhost" + """ + ) + result = testdir.runpytest( + "-p", + "no:base_url", + "--base-url", + "http://localhost", + "-W", + "error::pytest.PytestDeprecationWarning", + ) + result.assert_outcomes(passed=1) + + def test_base_url_without_plugin_autoload( testdir: pytest.Testdir, test_server: HTTPTestServer,