]> git.ipfire.org Git - thirdparty/patchwork.git/commitdiff
tests: Close XML-RPC client when done
authorStephen Finucane <stephen@that.guru>
Thu, 9 Apr 2020 09:46:13 +0000 (10:46 +0100)
committerStephen Finucane <stephen@that.guru>
Thu, 9 Apr 2020 09:49:23 +0000 (10:49 +0100)
This resolves the following irritating warnings that were popping up on
Python 3.7 and 3.8 and were silenced on 3.6:

  /usr/lib/python3.7/unittest/suite.py:107: ResourceWarning: unclosed <socket.socket ...>

Note that we need to use a subclass because the 'ServerProxy' class,
rather annoyingly, does not expose a 'close()' method. Instead, you're
expected to use a context manager, which isn't useful from the context
of a 'setUp' call. We could call '__enter__' and '__exit__' manually but
this seems cleaner. Also note that 'Server' was an alias of
'ServerProxy' [1], and we're taking the opportunity to switch here.

[1] https://docs.python.org/3/library/xmlrpc.client.html#xmlrpc.client.ServerProxy

Signed-off-by: Stephen Finucane <stephen@that.guru>
patchwork/tests/test_xmlrpc.py
tox.ini

index 6dcbca9b77c71d96936d07f9f296c56a6c46fb67..4726fdffa5d5660c0fe31744034ea54bfac30164 100644 (file)
@@ -13,6 +13,12 @@ from django.urls import reverse
 from patchwork.tests import utils
 
 
+class ServerProxy(xmlrpc_client.ServerProxy):
+
+    def close(self):
+        self.__close()
+
+
 @unittest.skipUnless(settings.ENABLE_XMLRPC,
                      'requires xmlrpc interface (use the ENABLE_XMLRPC '
                      'setting)')
@@ -20,7 +26,10 @@ class XMLRPCTest(LiveServerTestCase):
 
     def setUp(self):
         self.url = self.live_server_url + reverse('xmlrpc')
-        self.rpc = xmlrpc_client.Server(self.url)
+        self.rpc = ServerProxy(self.url)
+
+    def tearDown(self):
+        self.rpc.close()
 
 
 class XMLRPCGenericTest(XMLRPCTest):
@@ -55,7 +64,10 @@ class XMLRPCAuthenticatedTest(LiveServerTestCase):
         self.user = utils.create_maintainer(self.project)
         self.url = ('http://%s:%s@' + self.url[7:]) % (self.user.username,
                                                        self.user.username)
-        self.rpc = xmlrpc_client.Server(self.url)
+        self.rpc = ServerProxy(self.url)
+
+    def tearDown(self):
+        self.rpc.close()
 
     def test_patch_set(self):
         patch = utils.create_patch(project=self.project)
diff --git a/tox.ini b/tox.ini
index 8ba754706c4d1c7ae4b287083c8e742488cb17ad..75d893e1631bcd17e8789696289bfc5093355670 100644 (file)
--- a/tox.ini
+++ b/tox.ini
@@ -17,7 +17,8 @@ deps =
 setenv =
     DJANGO_SETTINGS_MODULE = patchwork.settings.dev
     PYTHONDONTWRITEBYTECODE = 1
-    py36: PYTHONWARNINGS = once,ignore::ResourceWarning:unittest.suite,ignore::ImportWarning:backports
+    PYTHONDEVMODE = 1
+    py36: PYTHONWARNINGS = once,ignore::ImportWarning:backports
     py{37,38}: PYTHONWARNINGS = once
 passenv =
     http_proxy HTTP_PROXY https_proxy HTTPS_PROXY no_proxy NO_PROXY