From 8c98d66014c59f7615998b8c0b449de8a55391c7 Mon Sep 17 00:00:00 2001 From: Wolfgang Schnerring Date: Fri, 13 Dec 2024 10:13:32 +0100 Subject: [PATCH] Remove automatic `base_url` override, this ever has worked only accidentally The order in which pytest plugins are loaded is currently nondeterministic, see pytest-dev/pytest#935. So we have no chance to override a fixture from another plugin in our plugin, this must instead be done in the project's conftest.py (which is guaranteed to have precedence over plugins). --- README.rst | 14 ++++++-------- src/zeit/nightwatch/pytest.py | 5 ----- tests/test_basics.py | 5 +++++ 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/README.rst b/README.rst index 378e8e4..ba98f15 100644 --- a/README.rst +++ b/README.rst @@ -122,18 +122,16 @@ Controlling a browser with playwright ===================================== As an alternative to Selenium (above) nightwatch also supports playwright; -mostly by pulling in the ``pytest-playwright`` plugin, so you can use their fixtures, with some convenience features: +mostly by pulling in the ``pytest-playwright`` plugin. -- Configure a base url, and then only use paths: - ``page.goto('/foo')`` +Unfortunately, the playwright API is too unfriendly to allow nightwatch to set the base url automatically, +so you'll need to do that yourself, for example by overriding the ``base_url`` fixture:: Example usage:: - @pytest.fixture(scope='session') - def nightwatch_config(): - return dict(selenium=dict( - baseurl='https://example.com', - )) + @pytest.fixture(scope="session") + def base_url(): + return 'https://example.com' def test_playwright_works(page): page.goto('/something') diff --git a/src/zeit/nightwatch/pytest.py b/src/zeit/nightwatch/pytest.py index bc09eb6..189babd 100644 --- a/src/zeit/nightwatch/pytest.py +++ b/src/zeit/nightwatch/pytest.py @@ -56,11 +56,6 @@ def selenium(selenium_session): selenium_session.delete_all_cookies() -@pytest.fixture(scope="session", autouse=True) -def base_url(nightwatch_config): # Overrides pytest-base-url - return nightwatch_config.get("selenium", {}).get("baseurl") - - @pytest.fixture(scope="session") def zeitde(nightwatch_environment): if nightwatch_environment == "production": diff --git a/tests/test_basics.py b/tests/test_basics.py index e742129..59c2fb0 100644 --- a/tests/test_basics.py +++ b/tests/test_basics.py @@ -10,6 +10,11 @@ def nightwatch_config(): ) +@pytest.fixture(scope="session") +def base_url(nightwatch_config): + return nightwatch_config.get("selenium", {}).get("baseurl") + + def test_get(http): r = http.get("/get") assert r.status_code == 200