Skip to content

Commit 0228b0e

Browse files
committed
Allow skipping the testcase that requires network
Not all test environments allow internet access, and one of the testcases relies on it by downloading an image over HTTPS. Add a check for access to dns.google that will skip it.
1 parent 38e95cf commit 0228b0e

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

tests/test_basicio.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
## along with this program. If not, see
1717
## <http://www.gnu.org/licenses/>.
1818

19+
import http.client
1920
import locale
2021
import os
2122
import shutil
@@ -26,13 +27,29 @@
2627
import exiv2
2728

2829

30+
# Source - https://stackoverflow.com/a/29854274
31+
# Posted by Ivelin, modified by community. See post 'Timeline' for change history
32+
# Retrieved 2026-03-16, License - CC BY-SA 4.0
33+
34+
def have_internet():
35+
conn = http.client.HTTPSConnection("dns.google", timeout=5)
36+
try:
37+
conn.request("HEAD", "/")
38+
return True
39+
except Exception:
40+
return False
41+
finally:
42+
conn.close()
43+
44+
2945
class TestBasicIoModule(unittest.TestCase):
3046
@classmethod
3147
def setUpClass(cls):
3248
test_dir = os.path.dirname(__file__)
3349
cls.image_path = os.path.join(test_dir, 'image_02.jpg')
3450
cls.data = b'The quick brown fox jumps over the lazy dog'
3551

52+
@unittest.skipUnless(have_internet(), 'Requires Internet access')
3653
@unittest.skipUnless(exiv2.versionInfo()['EXV_USE_CURL'],
3754
'CurlIo not included')
3855
def test_CurlIo(self):

0 commit comments

Comments
 (0)