Skip to content

test: use local httpserver for urllib tests - #562

Merged
miketheman merged 2 commits into
mainfrom
test-local-httpserver
Oct 21, 2026
Merged

miketheman merged 2 commits into
mainfrom
test-local-httpserver

Conversation

@miketheman

Copy link
Copy Markdown
Owner

The three urllib tests in tests/test_socket.py fetched https://http.codes/200, which now returns 503 Maintenance. That fails every macOS and Ubuntu job, including #561. This is the second public endpoint these tests have outlived: httpbin.org was replaced in #231 and httpstat.us in #426.

The tests now use the existing session httpserver fixture from conftest.py. --disable-socket and the disable_socket marker block socket construction regardless of host, so a loopback URL still tells allowed from blocked. I checked by breaking each test on purpose:

  • removing @pytest.mark.disable_socket lets the request through, and test_disabled_urllib_fails fails
  • removing @pytest.mark.enable_socket blocks the request, and test_enabled_urllib_succeeds fails
  • running the default test with --disable-socket blocks the request, and test_urllib_succeeds_by_default fails

These tests no longer go through DNS or TLS, but none of them asserted anything about either.

test_combinations.py (google.com, amazon.com, microsoft.com) and test_precedence.py:137 (DNS lookup of google.com) still need network access. They're left for a follow-up.

The three urllib tests in test_socket.py fetched https://http.codes/200,
which now returns 503 and fails every macOS and Ubuntu job. Point them
at the session httpserver fixture instead. --disable-socket and the
disable_socket marker block socket construction for any host, so
loopback still proves allow and block behavior.

Signed-off-by: Mike Fiedler <miketheman@gmail.com>
@codspeed

codspeed Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will degrade performance by 1.93%

1 warning

⚠️ Base and head ran on different runner types

Some benchmarks with significant performance changes were compared across different runner types, so the changes might not come from the code. Run base and head on the same runner type, or use CodSpeed Macro Runners for more stable results.

Learn more about Macro Runners

Open the report in CodSpeed to investigate

⚡ 1 improved benchmark
❌ 1 (👁 1) regressed benchmark
✅ 10 untouched benchmarks

Performance Changes

Benchmark BASE HEAD Efficiency
⚡ test_bench_host_from_connect_args 27.9 µs 20.1 µs +38.7%
👁 test_bench_host_from_connect_args_unix 18 µs 25.9 µs -30.66%

Tip

Curious why performance improved? Comment @codspeedbot explain why performance improved on this PR, or directly use the CodSpeed MCP with your agent.


Comparing test-local-httpserver (287eb0e) with main (92566a6)

Open in CodSpeed

The generated urllib tests were all named test_disable_socket_urllib,
including the two that expect the request to succeed. Name them
test_urllib, and drop the import pytest_socket lines that nothing
used.

Signed-off-by: Mike Fiedler <miketheman@gmail.com>
@miketheman
miketheman force-pushed the test-local-httpserver branch from 0e238ae to 287eb0e Compare October 21, 2026 12:52
@miketheman
miketheman merged commit 080ebb4 into main Oct 21, 2026
35 checks passed
@miketheman
miketheman deleted the test-local-httpserver branch October 21, 2026 12:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant