Skip to content

Commit a2b0850

Browse files
committed
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>
1 parent abfd2df commit a2b0850

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

patchwork/tests/test_xmlrpc.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,23 @@
1313
from patchwork.tests import utils
1414

1515

16+
class ServerProxy(xmlrpc_client.ServerProxy):
17+
18+
def close(self):
19+
self.__close()
20+
21+
1622
@unittest.skipUnless(settings.ENABLE_XMLRPC,
1723
'requires xmlrpc interface (use the ENABLE_XMLRPC '
1824
'setting)')
1925
class XMLRPCTest(LiveServerTestCase):
2026

2127
def setUp(self):
2228
self.url = self.live_server_url + reverse('xmlrpc')
23-
self.rpc = xmlrpc_client.Server(self.url)
29+
self.rpc = ServerProxy(self.url)
30+
31+
def tearDown(self):
32+
self.rpc.close()
2433

2534

2635
class XMLRPCGenericTest(XMLRPCTest):
@@ -55,7 +64,10 @@ def setUp(self):
5564
self.user = utils.create_maintainer(self.project)
5665
self.url = ('http://%s:%s@' + self.url[7:]) % (self.user.username,
5766
self.user.username)
58-
self.rpc = xmlrpc_client.Server(self.url)
67+
self.rpc = ServerProxy(self.url)
68+
69+
def tearDown(self):
70+
self.rpc.close()
5971

6072
def test_patch_set(self):
6173
patch = utils.create_patch(project=self.project)

tox.ini

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ deps =
1717
setenv =
1818
DJANGO_SETTINGS_MODULE = patchwork.settings.dev
1919
PYTHONDONTWRITEBYTECODE = 1
20-
py36: PYTHONWARNINGS = once,ignore::ResourceWarning:unittest.suite,ignore::ImportWarning:backports
20+
PYTHONDEVMODE = 1
21+
py36: PYTHONWARNINGS = once,ignore::ImportWarning:backports
2122
py{37,38}: PYTHONWARNINGS = once
2223
passenv =
2324
http_proxy HTTP_PROXY https_proxy HTTPS_PROXY no_proxy NO_PROXY

0 commit comments

Comments
 (0)