aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephen Finucane <stephen@that.guru>2020-04-09 10:46:13 +0100
committerStephen Finucane <stephen@that.guru>2020-04-09 10:49:23 +0100
commita2b08509275be5ab08d61e54fa2e430cef0b3442 (patch)
tree87145161296d77cf07afc52d1cdf2cf7c85df4c7
parentabfd2df5485d313a2835b60afdeb40731448b5b0 (diff)
downloadpatchwork-a2b08509275be5ab08d61e54fa2e430cef0b3442.tar
patchwork-a2b08509275be5ab08d61e54fa2e430cef0b3442.tar.gz
tests: Close XML-RPC client when done
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>
-rw-r--r--patchwork/tests/test_xmlrpc.py16
-rw-r--r--tox.ini3
2 files changed, 16 insertions, 3 deletions
diff --git a/patchwork/tests/test_xmlrpc.py b/patchwork/tests/test_xmlrpc.py
index 6dcbca9..4726fdf 100644
--- a/patchwork/tests/test_xmlrpc.py
+++ b/patchwork/tests/test_xmlrpc.py
@@ -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 8ba7547..75d893e 100644
--- 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