From: Bob Halley Date: Tue, 7 Dec 2021 14:01:35 +0000 (-0800) Subject: cope with 3.6 exception difference X-Git-Tag: v2.2.0rc1~15 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=911c317912cbe05f4b36da0289eec571ad8883cc;p=thirdparty%2Fdnspython.git cope with 3.6 exception difference --- diff --git a/tests/test_doh.py b/tests/test_doh.py index 9dc4cec7..6be7d211 100644 --- a/tests/test_doh.py +++ b/tests/test_doh.py @@ -17,6 +17,11 @@ import unittest import random import socket +try: + import ssl + _have_ssl = True +except Exception: + _have_ssl = False import dns.message import dns.query @@ -144,7 +149,7 @@ class DNSOverHTTPSTestCaseRequests(unittest.TestCase): self.assertTrue('8.8.4.4' in seen) -@unittest.skipUnless(dns.query._have_httpx and _network_available, +@unittest.skipUnless(dns.query._have_httpx and _network_available and _have_ssl, "Python httpx cannot be imported; no DNS over HTTPS (DOH)") class DNSOverHTTPSTestCaseHttpx(unittest.TestCase): def setUp(self): @@ -206,8 +211,9 @@ class DNSOverHTTPSTestCaseHttpx(unittest.TestCase): valid_tls_url = 'https://doh.cleanbrowsing.org/doh/family-filter/' q = dns.message.make_query('example.com.', dns.rdatatype.A) # make sure CleanBrowsing's IP address will fail TLS certificate - # check - with self.assertRaises(httpx.ConnectError): + # check. On 3.6 we get ssl.CertificateError instead of + # httpx.ConnectError. + with self.assertRaises((httpx.ConnectError, ssl.CertificateError)): dns.query.https(q, invalid_tls_url, session=self.session, timeout=4) # We can't do the Host header and SNI magic with httpx, but