Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
8 changes: 4 additions & 4 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v6
- name: Set up Python 3.14
uses: actions/setup-python@v5
uses: actions/setup-python@v6
with:
python-version: "3.14"
cache: "pip"
Expand All @@ -36,9 +36,9 @@ jobs:
python-version: ["3.9", "3.13", "3.14"]

steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v6
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
uses: actions/setup-python@v6
with:
python-version: ${{ matrix.python-version }}
cache: "pip"
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v6
- name: Set up Python
uses: actions/setup-python@v5
uses: actions/setup-python@v6
with:
Comment thread
thodson-usgs marked this conversation as resolved.
python-version: '3.x'
cache: 'pip'
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/sphinx-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
uses: actions/checkout@v6
with:
persist-credentials: false
- name: Set up Python
uses: actions/setup-python@v5
uses: actions/setup-python@v6
with:
python-version: "3.13"
cache: "pip"
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ dataretrieval = ["py.typed"]
test = [
"pytest > 5.0.0",
"pytest-cov[all]",
"pytest-rerunfailures",
"coverage",
"requests-mock",
"ruff",
Expand Down
41 changes: 41 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
"""Auto-retry live-API tests on transient upstream errors.

After PR #273, paginated ``waterdata`` getters propagate mid-walk HTTP
errors (429 / 5xx / connection drops) instead of silently truncating the
result. That's the correct behavior for users but makes any CI test that
hits the live USGS Water Data API susceptible to flaking on a transient
upstream blip — e.g. the HTTP 502 Bad Gateway that broke CI on PR #273's
merge to main.

Heuristic: any test that does NOT request the ``requests_mock`` fixture
is treated as live and gets retried on transient-error patterns only.
Library bugs raising other exception types still fail on the first try.
"""

import pytest

# Anchored loosely — the failure trace embeds the exception message
# after a long preamble.
_TRANSIENT_PATTERNS = [
r"RuntimeError:\s*(?:429|5\d\d):", # _raise_for_non_200 output
r"ConnectionError", # requests/urllib3
r"ReadTimeout|ConnectTimeout|Timeout",
]

# 5 seconds is generous enough for a USGS upstream replica to recover
# from a brief 5xx but short enough that CI doesn't drag.
_RETRY_DELAY_SEC = 5
_MAX_RERUNS = 2


def pytest_collection_modifyitems(config, items):
for item in items:
if "requests_mock" in item.fixturenames:
continue
item.add_marker(
pytest.mark.flaky(
reruns=_MAX_RERUNS,
reruns_delay=_RETRY_DELAY_SEC,
only_rerun=_TRANSIENT_PATTERNS,
)
)
Loading