microsoft / torchgeo

TorchGeo: datasets, samplers, transforms, and pre-trained models for geospatial data
https://www.osgeo.org/projects/torchgeo/
MIT License
2.67k stars 328 forks source link

Tests requiring internet access #1088

Open adamjstewart opened 1 year ago

adamjstewart commented 1 year ago

Description

Several of our tests require internet access. This is problematic for a number of reasons:

  1. The GitHub Actions runners or the upload servers may have internet issues, leading to intermittent failures
  2. Long download times slow down testing (the failing tests I discovered are all in our top 10 slowest tests)

We should apply the same magic we used in previous PRs to monkeypatch any downloads.

Steps to reproduce

  1. Turn off WiFi or unplug the ethernet cable
  2. Delete PyTorch's cached downloads: rm -r $(python -c 'import torch; print(torch.hub.get_dir())')
  3. Run pytest
FAILED tests/models/test_farseg.py::TestFarSeg::test_valid_backbone[resnet18-True] - urllib.error.URLError: <urlopen error [Errno 8] nodename nor servname provided, or not known>
FAILED tests/models/test_farseg.py::TestFarSeg::test_valid_backbone[resnet50-True] - urllib.error.URLError: <urlopen error [Errno 8] nodename nor servname provided, or not known>
FAILED tests/trainers/test_detection.py::TestObjectDetectionTask::test_trainer[True-faster-rcnn-nasa_marine_debris-NASAMarineDebrisDataModule] - urllib.error.URLError: <urlopen error [Errno 8] nodename nor ser...
FAILED tests/trainers/test_detection.py::TestObjectDetectionTask::test_trainer[True-fcos-nasa_marine_debris-NASAMarineDebrisDataModule] - urllib.error.URLError: <urlopen error [Errno 8] nodename nor servname p...
FAILED tests/trainers/test_detection.py::TestObjectDetectionTask::test_trainer[True-retinanet-nasa_marine_debris-NASAMarineDebrisDataModule] - urllib.error.URLError: <urlopen error [Errno 8] nodename nor servn...
FAILED tests/trainers/test_detection.py::TestObjectDetectionTask::test_no_rgb[True] - urllib.error.URLError: <urlopen error [Errno 8] nodename nor servname provided, or not known>
FAILED tests/trainers/test_detection.py::TestObjectDetectionTask::test_predict[True] - urllib.error.URLError: <urlopen error [Errno 8] nodename nor servname provided, or not known>

Version

0.5.0.dev0 (ce4e7ef2ed3ecff5731c2902d4cd3e8f5fab753d)

adamjstewart commented 1 year ago

Bonus points if anyone can figure out how to jail our runners so that we can actually test this in CI and prevent it from slipping in again. We seem to fix bugs like this with every release.

Note that many of our slow tests (run only on release branches) are actually designed to test these kinds of dataset and weight downloads. We should be able to get 100% coverage without internet access, but can add additional slow tests to ensure that the weights still download correctly.

adamjstewart commented 1 year ago

Related to #194 (fixed in #265) and #495 (fixed in #497)

adamjstewart commented 1 year ago

@calebrob6 I think the detection tests could use the same treatment from #344, that would greatly speed things up.

calebrob6 commented 1 year ago

~Do you want to add that as an issue so we don't lose track of it, or should we just do it now?~ I guess we can just leave this open?

adamjstewart commented 1 year ago

It can be done at the same time, using a fake detection model and avoiding downloads. Both will speed up the test and make it more stable.

adamjstewart commented 1 year ago

FarSeg tests were failing on main because of this. Would love to get these fixed.

adamjstewart commented 12 months ago

Update: slowly whittling these down:

FAILED tests/models/test_farseg.py::TestFarSeg::test_valid_backbone[resnet18-True] - urllib.error.URLError: <urlopen error [Errno 8] nodename nor servname provided, or not known>
FAILED tests/models/test_farseg.py::TestFarSeg::test_valid_backbone[resnet50-True] - urllib.error.URLError: <urlopen error [Errno 8] nodename nor servname provided, or not known>
FAILED tests/trainers/test_detection.py::TestObjectDetectionTask::test_pretrained_backbone - urllib.error.URLError: <urlopen error [Errno 8] nodename nor servname provided, or not known>
adamjstewart commented 1 month ago

Useful discussion (Linux-only):