Skip to content

geotiff tests: gate GPU and HTTP tests on runtime availability#1873

Merged
brendancol merged 2 commits into
mainfrom
issue-1872
May 14, 2026
Merged

geotiff tests: gate GPU and HTTP tests on runtime availability#1873
brendancol merged 2 commits into
mainfrom
issue-1872

Conversation

@brendancol
Copy link
Copy Markdown
Contributor

Closes #1872.

Summary

GPU tests in test_cog.py::TestGPUCOGOverviews and test_signature_annotations_1705.py gated on import cupy alone. A sandbox with cupy installed but no working CUDA runtime ran those tests instead of skipping. The remaining GPU test files already use a _gpu_available() helper that checks cupy.cuda.is_available(). This PR routes the two stragglers through the same check.

HTTP tests (test_http_*.py, test_cog_http_*.py) stand up a loopback HTTP server with socketserver.TCPServer(('127.0.0.1', 0), ...). Sandboxes that deny loopback bind error out instead of skipping. A collection hook in tests/conftest.py now probes loopback bind once and auto-skips any test module that imports socketserver, which covers every HTTP test in the directory without needing an explicit marker on each file.

Test plan

  • All 6 tests in test_http_range_validation_1735.py skip cleanly when _HAS_LOOPBACK=False is patched.
  • All 5 tests in test_cog.py::TestGPUCOGOverviews skip cleanly when gpu_available() is patched to return False.
  • Full xrspatial/geotiff/tests/ suite: 2635 passing, 7 skipped. The 8 remaining failures (test_predictor2_big_endian_gpu_1517.py, test_size_param_validation_gpu_vrt_1776.py::test_tile_size_positive_works, test_features.py::TestPalette) all reproduce on main and are tracked separately.

Two test infrastructure gaps caused noisy failures in restricted CI:

- test_cog.py::TestGPUCOGOverviews gated on import cupy alone, so a
  sandbox with cupy installed but no working CUDA runtime ran the tests
  instead of skipping. test_signature_annotations_1705.py had the same
  shape using importlib.util.find_spec.
- HTTP tests stand up loopback servers with TCPServer(('127.0.0.1', 0)).
  Sandboxes that deny loopback bind error out instead of skipping.

Add shared helpers in tests/conftest.py:

- gpu_available() probes cupy.cuda.is_available().
- loopback_available() probes a real socket bind once at collection.
- pytest_collection_modifyitems auto-skips any test module that imports
  socketserver when loopback is unavailable; every HTTP test in this
  directory does so to host its in-process server.

The two GPU files now route their skipif through gpu_available().
@github-actions github-actions Bot added the performance PR touches performance-sensitive code label May 14, 2026
@brendancol brendancol requested a review from Copilot May 14, 2026 19:53
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR makes GeoTIFF tests skip cleanly in restricted environments where CuPy is installed without usable CUDA, or loopback TCP binding is unavailable.

Changes:

  • Adds shared GPU/CUDA and loopback availability checks in GeoTIFF test conftest.py.
  • Adds a collection hook to skip socketserver-based tests when loopback bind is unavailable.
  • Updates remaining GPU-gated tests to use runtime CUDA availability instead of CuPy import presence.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
xrspatial/geotiff/tests/conftest.py Adds shared availability helpers, skip markers, and loopback-based collection skipping.
xrspatial/geotiff/tests/test_cog.py Switches GPU COG overview tests to skip unless CuPy + CUDA are available.
xrspatial/geotiff/tests/test_signature_annotations_1705.py Switches GPU writer smoke test to skip unless CuPy + CUDA are available.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +58 to +76
def pytest_collection_modifyitems(config, items):
"""Auto-skip tests that stand up a loopback HTTP server when the
sandbox denies socket bind. A test opts in implicitly by importing
``socketserver`` in its module; every HTTP test in this directory
does so to host a tiny in-process server.
"""
if _HAS_LOOPBACK:
return
skip_marker = pytest.mark.skip(
reason="loopback bind unavailable in this environment"
)
for item in items:
module = getattr(item, 'module', None)
if module is None:
continue
if 'socketserver' in vars(module):
item.add_marker(skip_marker)


…files

The module-level check skipped every test in a file that imports
socketserver. In files mixing HTTP and non-HTTP tests
(test_miniswhite_backend_parity_1797.py, test_cog_http_concurrent.py,
test_http_meta_buffer_1718.py) that suppressed coverage that does not
need loopback at all -- a GPU smoke test, four direct read_ranges
tests, and three in-memory metadata-buffer tests.

Replace the module-level check with per-test source inspection: a test
needs loopback iff its body or any fixture in its closure references
``socketserver.TCPServer(`` or ``_serve(``.
@brendancol
Copy link
Copy Markdown
Contributor Author

Addressed the per-test over-skip in bad8c7a. The module-level socketserver check was masking real coverage in mixed files; rewrote it as per-test source inspection of the function and its fixture closure for socketserver.TCPServer( or _serve(.

Verified under simulated no-loopback (socket.socket.bind patched to raise OSError on 127.0.0.1):

  • test_miniswhite_backend_parity_1797.py::test_gpu_miniswhite_matches_cpu_reader now PASSED (was SKIPPED); the two test_http_* tests in the same file still SKIPPED.
  • test_cog_http_concurrent.py: 4 test_read_ranges_* tests now PASSED; 2 test_cog_http_* tests still SKIPPED.
  • test_http_meta_buffer_1718.py: 2 in-memory tests + test_cap_raises_clear_error_on_excessive_chain now PASSED; test_end_to_end_http_read_with_big_metadata still SKIPPED.
  • Pure-HTTP test_http_range_validation_1735.py: all 6 tests still SKIPPED.

Full geotiff suite under normal loopback: 2643 passed, 3 skipped, 11 pre-existing failures (same as before).

@brendancol brendancol merged commit 02cade0 into main May 14, 2026
10 of 11 checks passed
@brendancol brendancol deleted the issue-1872 branch May 15, 2026 04:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

performance PR touches performance-sensitive code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

geotiff tests: GPU and HTTP tests fail in restricted CI environments

2 participants