Skip to content

Commit 047130f

Browse files
thodson-usgsclaude
andcommitted
Replace conftest auto-marking with module-level pytestmark
The previous conftest hook auto-applied pytest.mark.flaky to tests by inspecting function source for references to a central _PUBLIC_GETTERS frozenset. This was implicit and required keeping that set in sync with the public API. Switch to explicit opt-in: drop conftest.py and declare the marker at the top of waterdata_test.py via pytestmark. The other waterdata_*_test.py files are entirely mocked or pure unit tests and need no retry. The retry config (reruns count, delay, transient-error trace patterns) is co-located with the tests it protects. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 86ac286 commit 047130f

2 files changed

Lines changed: 18 additions & 100 deletions

File tree

tests/conftest.py

Lines changed: 0 additions & 100 deletions
This file was deleted.

tests/waterdata_test.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,24 @@
3333
_normalize_str_iterable,
3434
)
3535

36+
# Most tests in this module call the live USGS Water Data API. After
37+
# PR #273, transient upstream errors (5xx / 429 / connection drops)
38+
# propagate instead of silently truncating, which makes CI susceptible
39+
# to flaking on a brief upstream blip. Auto-retry such failures, but
40+
# only for the narrow set of transient-error trace patterns — library
41+
# bugs raising other exception types still fail on the first try.
42+
# Tests in this file that use ``requests_mock`` or ``mock.patch`` won't
43+
# match these patterns and so are effectively unaffected.
44+
pytestmark = pytest.mark.flaky(
45+
reruns=2,
46+
reruns_delay=5,
47+
only_rerun=[
48+
r"RuntimeError:\s*(?:429|5\d\d):", # _raise_for_non_200 output
49+
r"ConnectionError",
50+
r"ReadTimeout|ConnectTimeout|Timeout",
51+
],
52+
)
53+
3654

3755
def mock_request(requests_mock, request_url, file_path):
3856
"""Mock request code"""

0 commit comments

Comments
 (0)