* test: make `-m "not remote"` offline, and fix the 84 tests it selected that we…re not (GH-2003)
An autouse fixture in `tests/conftest.py` refuses non-local socket connections for every test
without the `remote` marker. A test that reaches upstream now fails at once naming the host,
rather than passing on a warm cache and failing on someone else's cold one -- which is what made
five reviewers of #2001 each report a different DWD failure as "the known throttling pattern",
every one of which had to be checked against the diff by hand.
Of the 84 tests the offline selection ran into the network, 58 are genuinely remote and were only
missing the marker. 25 reached upstream solely to get hold of an object and now build it from a
literal frame: the 21 date-arithmetic and url-parsing tests in `dwd/derived`, which downloaded
DWD's station index to parse `example.org/somefile_202510.csv`; the humanized-names mapping, which
is read off metadata; and three file-export error paths, which `_one_row()` already served beside
them. The last one is `filter_by_name`, which downloaded the whole station index before rapidfuzz
raised `TypeError` on a non-string name -- checked up front now, so the type test needs nothing.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
* test: raise the offline guard out of reach of the library's offline degradation (GH-2003)
The guard added in the previous commit raised `OSError`, which is the one thing
the library is built to absorb. aiohttp turns an `OSError` from a connect into
`ClientConnectorError`; `list_remote_files_fsspec` answers that with `[]`, and
`download_file` answers it with a `File` carrying `NoInternetError` that
`raise_if_exception` logs at debug and swallows. So the refusal never reached
the test:
- a test that needed a listing failed as `FileNotFoundError: url ... does not
have a list of files`, which reads like an upstream restructure rather than a
missing marker
- a test for which an empty listing is a legitimate answer passed while testing
nothing
`NetworkAccessBlockedError` derives straight from `Exception`, which is outside
every one of those handlers. Not `BaseException`, which would also escape them:
fsspec's `sync()` carries a result back from its loop thread through
`except Exception`, and anything outside that is dropped for a `None` return.
That surfaced two tests the swallowed guard had been hiding, both now `remote`:
`test_radar_request_site_historic_pe_future`, which asserts an empty result for
a year-2099 request and so passed on the refusal itself, and
`test_dwd_road_weather_station_groups`, whose non-strict xfail turned the
offline failure into an xfail inside the "offline" selection.
Also, rather than marking them: the eight duckdb `if_exists` tests now build
their frames with `_one_row`. Each tells its two writes apart by the station id
and asserts on `SELECT DISTINCT station_id`, so a request contributed a
one-station frame and a slow way to get a second string -- the network was never
what they were about, and marking them cost the offline selection all coverage
of `if_exists`.
The changelog entry overstated the `filter_by_name` change: rapidfuzz raised
`TypeError` for a non-string, but answered `None` with no matches, so `None`
used to come back as an empty result and now raises. Said, and pinned by a test.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
* test: fail a swallowed refusal at teardown, and unwrap mapped loopback (GH-2003)
Three gaps in the guard, all found by review.
`NetworkAccessBlockedError` derives from `Exception`, which keeps it clear of
the three handlers the library degrades on -- but not of the several call sites
that catch a bare `Exception`: `provider/dwd/dmo/api.py` twice, `is_valid()` in
`Wetterdienst.discover`, SMHI. An unmarked test over any of those would have
had its refusal turned into a log line and passed, which is the vacuous pass
the guard exists to stop. So the guard now records what it refused and
`_block_network` fails the test at teardown for a refusal that never arrived;
swallowing one postpones the failure rather than avoiding it. A
`blocked_network` fixture lets a test provoke the guard on purpose.
That teardown check then has to know whether the refusal already ended the
test, or the ordinary missing-marker case -- the guard's whole purpose --
reports twice, the second time saying a caller swallowed it when nothing did.
`pytest_runtest_makereport` stashes whether the call phase ended on the
refusal, and the check reads it. Both shapes are pinned, each as its own
session in its own process, because the guard's state is per process.
`is_loopback` is False for an IPv4-mapped `::ffff:127.0.0.1` on 3.12 and True
on 3.10, 3.11, 3.13 and 3.14 -- all five being in the CI matrix -- so a local
server reached over a dual-stack socket would have been refused on one of them.
`_is_local_address` unwraps `ipv4_mapped` before asking, and a mapped public
address stays refused.
Also: the `filter_by_name` changelog entry is a behaviour break -- `None` used
to come back as an empty result -- so it is filed as one, and says what to do
instead.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
* test: quiet the teardown check for a refusal raised during fixture setup (GH-2003)
The check reads a stash saying whether the refusal is what ended the test, and
that stash was only written for the call phase. A fixture that downloads
something -- an ordinary thing to write, and precisely what the guard exists to
diagnose -- raises during setup, so the stash stayed False and the check added
its second, contradictory error on top of the correct one.
Written for setup as well, and accumulated rather than assigned so the later
phase does not answer for the earlier one. A refusal raised in another
fixture's teardown still reports twice: that report is made after
`_block_network` has run its check, so there is nothing for the check to read.
Said in the hook's docstring rather than left to be discovered.
Also: `_one_row`'s docstring pointed at "the `if_exists` tests below", which
are above it -- the helper moved and the prose did not follow.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
* test: mark the one unmarked xfail test that fetches, and say why xfail defeats the check (GH-2003)
A non-strict `xfail` absorbs everything a test can report, the guard's teardown
check included: a bare `pytest.fail()` in a fixture's teardown comes back as a
second xfail and the run stays green. That is pytest, not this guard -- it
reproduces with no guard installed -- so no check made per test can catch a
test that is both unmarked and `xfail` and reaches upstream. It is the same
shape as `test_dwd_road_weather_station_groups`, whose xfail hid it earlier in
this branch.
`test_benchmarks` was the one left in the tree: unmarked, `xfail`, and its four
benchmark bodies all fetch DWD data. It stays offline today only because
scikit-learn is not installed, so an import error happens first. Marked
`remote`, and the gap itself is written down beside the other three the guard
does not cover.
The report hook now records a refusal only where the phase actually failed, so
the stash cannot claim one was reported when an xfail swallowed it. That does
not rescue the xfail case, and no longer says it does.
Also: the first assertion in `test_dwd_observations_stations_wrong_types` was
vacuous -- it passed `name=` to `filter_by_station_id`, which has no such
parameter, so the `TypeError` came from Python binding the arguments rather
than from the method. That method validates no types of its own, an int, a
float and an object all going through, so the line is dropped rather than
repaired into something that cannot exist.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
* test: name the host a refusal was for, and stop double-reporting a re-raised one (GH-2003)
Three things, all from review.
The docs said an unmarked test that reaches upstream "fails at once naming the
host". It did not: aiohttp and urllib3 both resolve first and hand `connect` an
address, so the refusal read `('141.38.2.164', 443)` and left the contributor to
look up whose server that is. Only a raw `sock.connect(("host", port))` ever
showed a name, which is why the guard's own tests did not catch it. Resolutions
are recorded as they happen, so the message is now
`opendata.dwd.de (141.38.2.164:443)` and the sentence is true as written.
`_REFUSAL_ENDED_TEST` only recognised the refusal unwrapped. A provider that
catches it and raises its own `from exc` -- several do -- left the stash False,
so the teardown check added its second report to a test that had already failed
loudly on the same cause. The traceback shows the chain either way, so the
whole chain is walked now, groups included.
`PYTHONPATH` was set rather than prepended for the subprocess tests, which
would drop an existing one under tox, conda or a CI image that sets it. It only
worked here because `uv run` does not.
`BaseExceptionGroup` is asked for by attribute rather than by name: 3.10 is
supported and does not have it.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
* test: refuse the name as well as the address, so the guard holds on Windows too (GH-2003)
`socket.connect` is not the path asyncio takes on Windows -- `ProactorEventLoop`
connects through `_overlapped.ConnectEx` -- so the library's whole download path
was unguarded there, and `-m "not remote"` would have gone green on Windows for
a test that fails everywhere else, while the docs called the selection enforced
without qualification. Resolution is the step every platform shares, so a name
off this machine is refused there as well, and the docs say names and addresses.
Two more from the same review:
`_is_local_address` compared the host case-sensitively, so `LOCALHOST` fell
through to `ip_address`, raised `ValueError` and was refused as if it were
upstream -- a test with a local server told to add `@pytest.mark.remote`.
The guard state was cleared after the `remote` early return rather than before
it, so a marked test asking for `blocked_network` would have been handed the
previous unmarked test's refusals as its own. Nothing does that today.
And the four duckdb tests `_one_row` had made byte-identical to the `if_exists`
tests above them go back to a real request, marked `remote`. Their names are
about the per-station frames `values.query()` yields and the frame `values.all()`
hands to `to_target`, and the rewrite had quietly dropped both while keeping the
names. The offline selection keeps the four `if_exists` tests it gained.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
* ci: run the offline selection as its own job, so "enforced" is something CI checks (GH-2003)
The branch documents `-m "not remote"` as enforced, and nothing enforced it.
Every job runs `poe test`, which is `-m 'not (explorer or cflake)'` and includes
the remote tests; no task ran the offline selection at all. Worse, running it
inside the full suite would not have asked the question: a `remote` test warms
the shared cache dir and the worker's fsspec session, so a later unmarked test
reading the same url is served from disk, opens no socket, and the guard sees
nothing to refuse.
So `poe test:offline` runs it on its own, and a job runs that. It is the one
job here that blocks: no network means no upstream to be down, which is what
makes the rest of the matrix `continue-on-error`. It carries none of the
provider credentials either -- nothing it selects may reach a provider, so
nothing it selects needs one.
Two smaller things from the same review. `_RESOLVED` was first-writer-wins, so
an address fronting several names kept whichever was asked for first and the
refusal could name the wrong host; last writer wins now. And the guard's record
is per process rather than per test, so a connection from a thread an earlier
`remote` test left running would be charged to whichever unmarked test is
current -- nothing tells the two apart at the socket, so it is written down
beside the other limits, and `test:offline` is a run where nothing is left
behind to begin with.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
* test: keep cflake tests out of the parallel offline run, and drop the dead naming table (GH-2003)
Four from review, the first of which undid a good part of the job added last
commit.
`test:offline` ran `-m 'not remote'` under `--numprocesses=auto`, which selects
the two `cflake` tests in `tests/util/test_network.py` and runs them in the
xdist pool -- the concurrency that marker exists to keep them out of. On the one
job here that blocks, that is the only test failure that can turn the workflow
red. They run serially now, as `test:cflakes` already runs the rest.
The `_RESOLVED` table and `_describe` were dead. They were added so a refusal at
`connect` could name the host aiohttp had already resolved, and the commit after
them started refusing resolution itself -- so nothing non-local is ever resolved
to record, and the refusal carries the name because the name is what it refused.
Removed, along with the two tests that only passed by injecting the mapping.
The teardown check now runs only where the selection has no `remote` test in it.
What the guard records is per process: a connection from a thread an earlier
`remote` test left running is refused while some unmarked test is current, and
the record would make it that test's. Nothing tells those apart at the socket,
and failing a correct test is worse than missing a swallowed refusal. The
refusal is raised in either run; only `test:offline`, which CI gates on, has
nothing left behind to misattribute. The hook that decides is `trylast`, because
deselecting on `-m` happens in that same hook and any earlier every run looks
mixed.
And the blocking job runs 3.10, 3.12 and 3.14 rather than 3.13 alone: those are
the versions the guard reasons about -- 3.10 has no `BaseExceptionGroup`, 3.12
is the one that calls a v4-mapped loopback address not a loopback -- and the
matrix that covers them all is `continue-on-error`.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
* test: refuse a bytes host too, and stop the CI comment claiming a rule the repo has not got (GH-2003)
`_guarded_getaddrinfo` asked whether the host was a `str`, so a bytes host went
straight to the real resolver. `socket.getaddrinfo(b"opendata.dwd.de", 443)` is
valid Python and asyncio's `_ensure_resolved` passes the host through unchanged,
so a caller handing the loop bytes was unguarded -- and on Windows, where
`connect` is not on the Proactor path, that is the whole download path again,
which is the hole the resolution guard was added to close. Decoded before the
check now, which also leaves `None` -- meaning this machine, and how a local
server asks for something to bind to -- to `_is_local_address` as before.
The new job's comment said it blocks. It does not: the repo's active ruleset has
`deletion`, `non_fast_forward`, `required_signatures`, `pull_request`,
`code_quality` and `code_scanning`, and no `required_status_checks` rule at all,
so nothing in this workflow is a required check. It says what is true instead --
that a red here is a real regression rather than a provider having a bad
morning, which is why it is not `continue-on-error` -- and says plainly that it
reports rather than stops a merge.
`_block_network` is annotated `Generator[None]`, which is what it is.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
* test: assert the resolver the name-level guard rests on (GH-2003)
Refusing at `getaddrinfo` only reaches aiohttp while aiohttp resolves through
it. `DefaultResolver` is `AsyncResolver` the moment `aiodns` is importable --
aiohttp's usual speedups dependency, which can arrive transitively without
anyone asking for it -- and `AsyncResolver` goes through c-ares, which this
never sees. On Windows the `connect` patch is already off the path, so that day
the whole download path would be unguarded and the offline selection would go
quietly green, with nothing in this file going red: the existing test calls
`socket.getaddrinfo` itself and passes either way.
Asserted now, so the day it changes someone decides what to do about it.
Two smaller ones. The `_REFUSAL_ENDED_TEST` stash is reset per attempt, since
pytest-rerunfailures hands the same `Item` to each and a retry would otherwise
read the first attempt's answer. And `test:offline`'s `explorer` exclusion says
why it is there -- it mirrors `test:parallel`, and there are no such tests.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
* test: ask the guard's own tests by name, so they hold on Windows too (GH-2003)
`test_a_blocked_listing_says_so_rather_than_coming_back_empty` and
`test_a_blocked_download_says_so_rather_than_carrying_no_internet` addressed a
literal `192.0.2.1`. aiohttp and asyncio both skip resolution for a literal, so
those two rested on the `connect` patch alone -- and that patch is not on the
path on Windows, where asyncio connects through `_overlapped.ConnectEx`. They
would have passed here and failed on the windows leg of the matrix, each after
waiting out three real connect timeouts to a blackholed address.
They ask for a name now, one RFC 2606 reserves so it resolves nowhere, which
puts them on the guard every platform shares. Checked by taking the connect
patch off and running them: still refused, and the record reads
`('blocked.invalid', 443)`, so it is the name guard answering.
And the claim in AGENTS.md and the contributing page was unqualified where
`tests/conftest.py` lists four things it does not cover. Both now say the guard
catches a connection being made rather than one already open, and point at the
list.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
* docs: name the task CI actually runs, and give the teardown gate its real reason (GH-2003)
The contributing page said `poe test:offline` is how CI asks the question. The
job runs `test:offline:all`; `test:offline` alone deselects the two `cflake`
tests that `test:offline:cflakes` adds back serially, so a contributor
reproducing the job from the page ran a smaller selection than it does.
And the gate on the teardown check was justified only by the offline selection
having no `remote` test to leave a thread behind, which is not the whole reason
and would not be enough on its own -- an unmarked test can outlive its own
connection attempt just as well. The reason it is safe there is stronger: every
non-local name and address is refused before any I/O, so in that run no socket
to one is ever opened, nothing is left waiting on one, and no attempt can arrive
late to be charged to an innocent test. Said properly.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
* test: read a bytes host at connect too, and stop the check diagnosing a cause it cannot know (GH-2003)
`_guarded_getaddrinfo` learned to decode a bytes host two commits ago; the
`connect` path was left on `str()`, where `str(b"127.0.0.1")` is
`"b'127.0.0.1'"` -- matching no loopback, so a legitimate local connection made
with a bytes host was refused as if it were upstream. It fails closed, so it
could only ever have produced a false failure, never a leak. Both paths decode
the same way now.
The teardown check said "the refusal did not reach the test, so something on the
way caught it". Usually true, and for a refusal raised in another fixture's
teardown it is not: that report is made after this check has run, nothing caught
anything, and the sentence sends the reader looking for an `except Exception`
that is not there. It says what is known instead -- that neither the setup nor
the call phase reported it, so it was caught on the way or raised during
teardown.
And `test:offline:cflakes` excluded `remote` but not `explorer`, so the pair did
not partition what the page says it does: an `explorer` test that was not
`cflake` would have been run by neither. Nothing is marked `explorer` today.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
* test: assert the set of refusals on the download path, as the listing test does (GH-2003)
The exact list holds only because `_worth_retrying_download` does not match
`NetworkAccessBlockedError` today. Broaden that predicate -- to `on=Exception`,
say, which the listing path already uses -- and the assertion fails in a file
about the network guard, pointing at the guard rather than at the retry policy
that changed. How many attempts are made is that predicate's business; what this
test is about is that nothing but this address was reached.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
* test: name the real boundary the guard is installed behind (GH-2003)
The list of what it does not cover said "at import time or by a session-scoped
fixture". Fixtures are set up widest first and this one is function-scoped, so
package, module and class scopes are all ahead of it too -- and a fixture at any
of them that downloads something is unguarded and unrecorded, which the list
exists to say. Nothing under `tests/` is scoped above `function` today.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
* docs: say which connects Windows misses, and point a new test at the offline task (GH-2003)
`_guarded_getaddrinfo` said "the connect patch misses Windows entirely". It does
not: a synchronous `socket.connect` is guarded there like anywhere else. What it
misses is asyncio, whose `ProactorEventLoop` goes through `_overlapped.ConnectEx`
-- which happens to be the library's whole download path, which is why the
resolution guard exists. Read loosely, the old sentence invited someone to drop
the connect patch on Windows as dead weight.
And AGENTS.md listed only `poe test`, which runs the remote tests too and so
warms the cache and the connection an unmarked test would then be served from --
the very mechanism the new task exists for. A contributor checking a new test
that way gets a pass and hears about it from CI. `test:offline:all` is in the
command list now, and the marker note says to use it.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
* ci: run the offline selection on Windows too, and let the cflake leg collect nothing (GH-2003)
The resolution guard exists because `socket.connect` is not asyncio's path on
Windows -- `ProactorEventLoop` connects through `_overlapped.ConnectEx` -- and
nothing in CI ever asked whether the selection is offline there. The Windows leg
of the matrix runs `poe test`, remote tests and all, which warms the cache and
the connection an unmarked test would then be served from, so it cannot ask.
`tests/test_network_guard.py` proves the guard is installed; it does not prove
the suite is offline. The offline job runs a Windows leg now, which does.
And `test:offline:cflakes` selects two tests, both in `tests/util/test_network.py`.
Mark them `remote` and pytest exits 5 for collecting nothing, which poe reads as
failure -- so the offline job would go red with "no tests ran" in a job whose
value is that a red one means a real regression. Exit 5 is tolerated, and the
task names bash as its interpreter rather than relying on poe's default `sh`,
which the Windows leg has not got.
Also a wrap artifact in the `_block_network` docstring, which AGENTS.md now
points contributors at.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
* test: guard the other two ways in to the resolver (GH-2003)
`socket.gethostbyname` and `gethostbyname_ex` are their own C entry points and
never reach the patched `socket.getaddrinfo`, so an unmarked test resolving that
way got an address back with nothing refused and nothing recorded -- verified
before the fix: `socket.gethostbyname("opendata.dwd.de")` answered
`141.38.2.164` and the test passed. A caller resolving that way has the address
in hand and can then connect by the path the connect patch does not see on
Windows, which is the hole the name-level refusal exists to close. Nothing in
the tree resolves this way today, aiohttp's `ThreadedResolver` going through
`loop.getaddrinfo`.
The three entry points share one refusal now rather than repeating it.
The test looks its resolver up by name at call time. Parametrising on the
attribute captures it at collection, which is before the guard is installed, so
the first version of this test measured the unpatched function and would have
passed whatever the guard did.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
* ci: run the offline selection as one serial job, dropping the split that could go green empty (GH-2003)
`test:offline:cflakes` mapped pytest's exit 5 to success so that marking its two
tests `remote` would not red the job with "no tests ran". That trades a false
red for a false green: rename the marker or mark both tests, the leg matches
nothing, exits 0, and the offline property stops being checked by a job whose
whole value is that green means checked.
The split existed because `test:offline` ran under xdist, which is the
concurrency the `cflake` marker is about. Running the whole selection serially
removes the reason for it: 30s against 13s, for one task that always collects,
no exit code to special-case, no second marker expression to keep in step with
the first, and the `cflake` tests run the way their marker asks. `poe test`
keeps its parallel split; this is the job that has 30s to spare.
Also `_refuse_name`'s docstring said `None` "means this machine, which
`_is_local_address` already answers for". It never asks: a host that is neither
`str` nor bytes is left alone without being consulted. Same outcome, but the
next person deciding whether to widen that check will read this line.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>