Commit 7cf9b87
Auto-retry live-API tests on transient upstream errors
#273 surfaced a transient HTTP 502 from upstream on its merge-to-main
CI run that pre-PR-273 would have been silently swallowed by
_walk_pages and turned into an empty DataFrame. The status-code-aware
behavior is correct for users, but it makes every test that hits the
live USGS Water Data API susceptible to flaking on a transient blip.
This PR adds:
- pytest-rerunfailures to the `test` optional dependency set.
- tests/conftest.py that (a) registers a `live` pytest marker; (b)
auto-applies it to every test that does not take `requests_mock` as
a fixture (the existing mock-driven convention in this repo); and
(c) configures live-marked tests to retry up to twice on a 5-second
backoff — but ONLY when the failure trace matches one of a narrow
set of transient-upstream patterns: `429:` / `5xx:` prefixes from
`_raise_for_non_200`, `ConnectionError` shapes, and timeout strings
from the requests/urllib3 stack.
Library bugs raising other exception types are not retried — the
`only_rerun` pattern set deliberately matches on the failure-text
shape produced by `_raise_for_non_200` rather than on generic
`RuntimeError`, so a real bug fails on the first attempt.
Verified: pytest collection identifies 59 of 61 tests in
waterdata_test.py as live (the two `*_mock_*` tests correctly stay
unmarked). Offline tests (`_get_args`, `_check_*`, `_normalize_str_*`,
`_construct_api_requests_*`) pass unchanged.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 0a14ba5 commit 7cf9b87
3 files changed
Lines changed: 74 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
1 | 3 | | |
2 | 4 | | |
3 | 5 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
| 38 | + | |
38 | 39 | | |
39 | 40 | | |
40 | 41 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
0 commit comments