diff options
author | Stephen Finucane <stephen@that.guru> | 2020-04-09 10:46:13 +0100 |
---|---|---|
committer | Stephen Finucane <stephen@that.guru> | 2020-04-09 10:49:23 +0100 |
commit | a2b08509275be5ab08d61e54fa2e430cef0b3442 (patch) | |
tree | 87145161296d77cf07afc52d1cdf2cf7c85df4c7 | |
parent | abfd2df5485d313a2835b60afdeb40731448b5b0 (diff) | |
download | patchwork-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.py | 16 | ||||
-rw-r--r-- | tox.ini | 3 |
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) @@ -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 |