# HG changeset patch # Parent e2b09c00ee24ecc3ddb55e520dd8f8a74b65a9cc Issue #19756: Avoid a timed out NNTP connection failing subsequent tests Now each test method creates a new NNTP connection. The downside is all the reconnecting slows the test execution from 42 s down to 115 s. diff -r e2b09c00ee24 Lib/test/test_nntplib.py --- a/Lib/test/test_nntplib.py Sat Jun 18 15:58:52 2016 -0400 +++ b/Lib/test/test_nntplib.py Sat Dec 24 02:52:59 2016 +0000 @@ -208,9 +208,7 @@ resp, caps = self.server.capabilities() _check_caps(caps) - def test_zlogin(self): - # This test must be the penultimate because further commands will be - # refused. + def test_login(self): baduser = "notarealuser" badpw = "notarealpassword" # Check that bogus credentials cause failure @@ -221,13 +219,8 @@ # test suite, I think. Gmane is anonymous, at least as used for the # other tests. - def test_zzquit(self): - # This test must be called last, hence the name - cls = type(self) - try: - self.server.quit() - finally: - cls.server = None + def test_quit(self): + self.server.quit() @classmethod def wrap_methods(cls): @@ -280,16 +273,14 @@ NNTP_CLASS = NNTP - @classmethod - def setUpClass(cls): + def setUp(self): support.requires("network") - with support.transient_internet(cls.NNTP_HOST): - cls.server = cls.NNTP_CLASS(cls.NNTP_HOST, timeout=TIMEOUT, usenetrc=False) + with support.transient_internet(self.NNTP_HOST): + self.server = self.NNTP_CLASS(self.NNTP_HOST, timeout=TIMEOUT, usenetrc=False) - @classmethod - def tearDownClass(cls): - if cls.server is not None: - cls.server.quit() + def tearDown(self): + with self.server: + pass @unittest.skipUnless(ssl, 'requires SSL support') class NetworkedNNTP_SSLTests(NetworkedNNTPTests):