Skip to content
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Copyright (c) Microsoft Corporation.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Provides the base_url fixture when pytest-base-url is not in use, see
# pytest_load_initial_conftests in pytest_playwright.py. It is a module rather
# than a class instance, as pytest 9.2 deprecates session-scoped fixtures defined
# as instance methods: https://github.com/microsoft/playwright-pytest/issues/341

from typing import Any, Optional

import pytest


@pytest.fixture(scope="session")
def base_url(pytestconfig: Any) -> Optional[str]:
return (
pytestconfig.getoption("--base-url") or pytestconfig.getini("base_url") or None
)
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@
import traceback
import urllib.parse

from pytest_playwright_asyncio import _base_url_fallback


@pytest.fixture(scope="session")
def _pw_artifacts_folder(
Expand Down Expand Up @@ -818,7 +820,7 @@ def pytest_load_initial_conftests(
default=os.getenv("PYTEST_BASE_URL", None),
help="base url for the application under test.",
)
early_config.pluginmanager.register(_BaseUrlFallback(), "playwright-base-url")
early_config.pluginmanager.register(_base_url_fallback, "playwright-base-url")


def _is_pytest_base_url_loaded(pluginmanager: pytest.PytestPluginManager) -> bool:
Expand All @@ -828,17 +830,6 @@ def _is_pytest_base_url_loaded(pluginmanager: pytest.PytestPluginManager) -> boo
return module is not None and pluginmanager.is_registered(module)


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]:
return (
pytestconfig.getoption("--base-url")
or pytestconfig.getini("base_url")
or None
)


class ArtifactsRecorder:
def __init__(
self,
Expand Down
29 changes: 29 additions & 0 deletions pytest-playwright/pytest_playwright/_base_url_fallback.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Copyright (c) Microsoft Corporation.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Provides the base_url fixture when pytest-base-url is not in use, see
# pytest_load_initial_conftests in pytest_playwright.py. It is a module rather
# than a class instance, as pytest 9.2 deprecates session-scoped fixtures defined
# as instance methods: https://github.com/microsoft/playwright-pytest/issues/341

from typing import Any, Optional

import pytest


@pytest.fixture(scope="session")
def base_url(pytestconfig: Any) -> Optional[str]:
return (
pytestconfig.getoption("--base-url") or pytestconfig.getini("base_url") or None
)
15 changes: 3 additions & 12 deletions pytest-playwright/pytest_playwright/pytest_playwright.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@
import traceback
import urllib.parse

from pytest_playwright import _base_url_fallback


@pytest.fixture(scope="session")
def _pw_artifacts_folder(
Expand Down Expand Up @@ -815,7 +817,7 @@ def pytest_load_initial_conftests(
default=os.getenv("PYTEST_BASE_URL", None),
help="base url for the application under test.",
)
early_config.pluginmanager.register(_BaseUrlFallback(), "playwright-base-url")
early_config.pluginmanager.register(_base_url_fallback, "playwright-base-url")


def _is_pytest_base_url_loaded(pluginmanager: pytest.PytestPluginManager) -> bool:
Expand All @@ -825,17 +827,6 @@ def _is_pytest_base_url_loaded(pluginmanager: pytest.PytestPluginManager) -> boo
return module is not None and pluginmanager.is_registered(module)


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]:
return (
pytestconfig.getoption("--base-url")
or pytestconfig.getini("base_url")
or None
)


class ArtifactsRecorder:
def __init__(
self,
Expand Down
4 changes: 3 additions & 1 deletion tests/test_asyncio.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,9 @@ async def test_base_url(page, base_url):
"""
)
result = testdir.runpytest(*args)
result.assert_outcomes(passed=1)
# The fallback fixture must not trip pytest's deprecations, see
# https://github.com/microsoft/playwright-pytest/issues/341
result.assert_outcomes(passed=1, warnings=0)


def test_base_url_without_plugin_autoload(
Expand Down
4 changes: 3 additions & 1 deletion tests/test_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,9 @@ def test_base_url(page, base_url):
"""
)
result = testdir.runpytest(*args)
result.assert_outcomes(passed=1)
# The fallback fixture must not trip pytest's deprecations, see
# https://github.com/microsoft/playwright-pytest/issues/341
result.assert_outcomes(passed=1, warnings=0)


def test_base_url_without_plugin_autoload(
Expand Down
Loading