]> granicus.if.org Git - python/commitdiff
Issue #22351: Fix test_nntplib if the ssl module is missing
authorVictor Stinner <victor.stinner@gmail.com>
Fri, 3 Apr 2015 09:06:40 +0000 (11:06 +0200)
committerVictor Stinner <victor.stinner@gmail.com>
Fri, 3 Apr 2015 09:06:40 +0000 (11:06 +0200)
@unittest.skipUnless(ssl, '...') doesn't work because the class body uses the
nntplib.NNTP_SSL attribute which doesn't exist.

Lib/test/test_nntplib.py

index 9e88ddbda7b9de169d5a2ef813a30be1a66c7400..9a8067434ced14a74cc61eb84e9ef0fe041752ea 100644 (file)
@@ -1509,15 +1509,16 @@ class MockSocketTests(unittest.TestCase):
             Handler, nntplib.NNTPPermanentError, authinfo_response,
             login, password)
 
-@unittest.skipUnless(ssl, 'requires SSL support')
-class MockSslTests(MockSocketTests):
-    class nntp_class(nntplib.NNTP_SSL):
-        def __init__(self, *pos, **kw):
-            class bypass_context:
-                """Bypass encryption and actual SSL module"""
-                def wrap_socket(sock, **args):
-                    return sock
-            return super().__init__(*pos, ssl_context=bypass_context, **kw)
+if ssl is not None:
+    class MockSslTests(MockSocketTests):
+        class nntp_class(nntplib.NNTP_SSL):
+            def __init__(self, *pos, **kw):
+                class bypass_context:
+                    """Bypass encryption and actual SSL module"""
+                    def wrap_socket(sock, **args):
+                        return sock
+                return super().__init__(*pos, ssl_context=bypass_context, **kw)
+
 
 if __name__ == "__main__":
     unittest.main()