Skip to content

Commit 7edc6c9

Browse files
gutzbenjclaude
andcommitted
test: raise the pytest floor to 9.2, and take the workaround for 9.1 back (GH-3859)
`test_mcp_auth_tool_answers_as_the_route_does` failed in a selection that names `tests/ui` files on both sides of a file outside it. That is a regression of pytest 9.1.0 and 9.1.1 (pytest-dev/pytest#14635, "fixtures not found when a parent directory appears multiple times in a argument list"), fixed in 9.2.0 (pytest-dev/pytest#14645): the autouse fixtures of a sub-directory's conftest did not reach the tests of the second node pytest made for that directory, so `_forget_auth_probes` of `tests/ui/conftest.py` did not run for `test_core.py` and `test_restapi.py`, and the probe that an earlier test left in the cache answered the MCP test. The floor of the dev group is `pytest>=9.2` instead (uv.lock: pytest 9.1.1 to 9.2.0 only). `tests/ui/conftest.py` and its fixture are as on main, and the workaround of the first commit of this branch, with its guard test, is gone. Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_0187kUCUFKYgEkY8mDbH23V8
1 parent 52b7598 commit 7edc6c9

5 files changed

Lines changed: 27 additions & 60 deletions

File tree

‎pyproject.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ dev = [
278278
"matplotlib>=3.10,<4",
279279
# in-memory span and metric readers for the tests of the REST API's OpenTelemetry
280280
"opentelemetry-sdk>=1.45",
281-
"pytest>=9.1",
281+
"pytest>=9.2",
282282
"pytest-cov>=7.1",
283283
# 16.7 matches `--only-rerun` against the cause chain too, which tests/conftest.py's `_rerun_will_retry` models
284284
"pytest-rerunfailures>=16.7",

‎tests/conftest.py‎

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -392,28 +392,6 @@ def _no_fetch_ahead_unless_asked_for(request: pytest.FixtureRequest) -> Generato
392392
TimeseriesValues._fetch_ahead = original # type: ignore[method-assign] # noqa: SLF001
393393

394394

395-
def _clear_auth_probes() -> None:
396-
"""Drop the credential probes of `get_auth`, if the module that holds them has been imported."""
397-
core = sys.modules.get("wetterdienst.ui.core")
398-
if core is not None:
399-
core._auth_probes.clear() # noqa: SLF001
400-
401-
402-
@pytest.fixture(autouse=True)
403-
def _forget_auth_probes() -> Generator[None]:
404-
"""Start and end every test with no answer of a credential probe kept, as `get_auth` reuses them for a minute.
405-
406-
Here and not in `tests/ui/conftest.py`, where it was (GH-3859): pytest 9 ties the autouse fixtures of a
407-
sub-directory's conftest to the directory node it loaded the conftest for. A selection that names files of that
408-
directory on both sides of a file outside it (`pytest tests/ui/a.py tests/b.py tests/ui/c.py`) gets a second node
409-
for the directory, and the tests of `c.py` run without the fixture. Those of this root conftest reach every
410-
test. The cache lives in a module a test may not have imported, and one that was not has nothing to clear.
411-
"""
412-
_clear_auth_probes()
413-
yield
414-
_clear_auth_probes()
415-
416-
417395
def _is_local_address(address: object) -> bool:
418396
"""Say whether a socket address points at this machine.
419397

‎tests/ui/conftest.py‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Copyright (C) 2018-2025, earthobservations developers.
2+
# Distributed under the MIT License. See LICENSE for more info.
3+
"""Fixtures of the surface tests."""
4+
5+
from __future__ import annotations
6+
7+
from typing import TYPE_CHECKING
8+
9+
import pytest
10+
11+
from wetterdienst.ui import core
12+
13+
if TYPE_CHECKING:
14+
from collections.abc import Generator
15+
16+
17+
@pytest.fixture(autouse=True)
18+
def _forget_auth_probes() -> Generator[None]:
19+
"""Start and end every test with no answer of a credential probe kept, as `get_auth` reuses them for a minute."""
20+
core._auth_probes.clear() # noqa: SLF001
21+
yield
22+
core._auth_probes.clear() # noqa: SLF001

‎tests/ui/test_auth_cache.py‎

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,7 @@
44

55
from __future__ import annotations
66

7-
import subprocess
8-
import sys
97
import threading
10-
from pathlib import Path
118

129
import pytest
1310
from fastapi.testclient import TestClient
@@ -237,33 +234,3 @@ def test_an_unknown_network_adds_no_key(probes: list[object]) -> None:
237234
assert response.status_code == 404
238235
assert probes == []
239236
assert core._auth_probes._entries == {} # noqa: SLF001
240-
241-
242-
def test_the_probes_are_forgotten_before_every_test_whatever_the_order_of_the_selection() -> None:
243-
"""A test is given the reset of the probes even where a selection names `tests/ui` files on both sides of another.
244-
245-
pytest 9 gives the autouse fixtures of a sub-directory's conftest to the first node it makes for that directory:
246-
the files after a file outside it, in a selection that names that directory twice, ran without them, and a probe
247-
a test had left in the cache answered the next one's `/api/auth` (GH-3859). The fixture is in `tests/conftest.py`.
248-
"""
249-
selection = ["tests/ui/test_auth_cache.py", "tests/test_info.py", "tests/ui/test_probe_head.py"]
250-
result = subprocess.run( # noqa: S603
251-
[sys.executable, "-m", "pytest", *selection, "--setup-plan", "-p", "no:cacheprovider"],
252-
cwd=Path(__file__).parents[2],
253-
capture_output=True,
254-
text=True,
255-
timeout=120,
256-
check=False,
257-
)
258-
259-
assert result.returncode == 0, result.stdout[-2000:] + result.stderr[-2000:]
260-
plans: dict[str, set[str]] = {}
261-
current = ""
262-
for line in result.stdout.splitlines():
263-
if line.startswith("tests/"):
264-
current = line.split()[0]
265-
plans[current] = set()
266-
elif current and "SETUP" in line:
267-
plans[current].add(line.split()[-1])
268-
assert plans
269-
assert {nodeid for nodeid, setups in plans.items() if "_forget_auth_probes" not in setups} == set()

‎uv.lock‎

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)