From 58991bd8b703b6427989b6f3afaa3264a60b61b8 Mon Sep 17 00:00:00 2001 From: Bradley Laney Date: Wed, 4 Jul 2018 14:36:57 -0400 Subject: [PATCH 1/2] bpo-34031: fix incorrect usage of self.fail in 2 unittests --- Lib/test/test_file.py | 2 +- Lib/test/test_urllib2_localnet.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_file.py b/Lib/test/test_file.py index 9890b8c586f380..167bf887c41706 100644 --- a/Lib/test/test_file.py +++ b/Lib/test/test_file.py @@ -242,7 +242,7 @@ def testIteration(self): for methodname, args in methods: f = self.open(TESTFN, 'rb') if next(f) != filler: - self.fail, "Broken testfile" + self.fail("Broken testfile") meth = getattr(f, methodname) meth(*args) # This simply shouldn't fail f.close() diff --git a/Lib/test/test_urllib2_localnet.py b/Lib/test/test_urllib2_localnet.py index 52c897af433cce..3ae1b3cf22e1fc 100644 --- a/Lib/test/test_urllib2_localnet.py +++ b/Lib/test/test_urllib2_localnet.py @@ -306,7 +306,7 @@ def test_basic_auth_success(self): try: self.assertTrue(urllib.request.urlopen(self.server_url)) except urllib.error.HTTPError: - self.fail("Basic auth failed for the url: %s", self.server_url) + self.fail(f"Basic auth failed for the url: {self.server_url}") def test_basic_auth_httperror(self): ah = urllib.request.HTTPBasicAuthHandler() From 67dfc3143e844464db53dedfbe69646415fb9cd5 Mon Sep 17 00:00:00 2001 From: Bradley Laney Date: Thu, 5 Jul 2018 18:16:35 -0400 Subject: [PATCH 2/2] requested changes --- Lib/test/test_file.py | 3 +-- Lib/test/test_urllib2_localnet.py | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/Lib/test/test_file.py b/Lib/test/test_file.py index 167bf887c41706..f58d1dae6045f4 100644 --- a/Lib/test/test_file.py +++ b/Lib/test/test_file.py @@ -241,8 +241,7 @@ def testIteration(self): # Test for appropriate errors mixing read* and iteration for methodname, args in methods: f = self.open(TESTFN, 'rb') - if next(f) != filler: - self.fail("Broken testfile") + self.assertEqual(next(f), filler) meth = getattr(f, methodname) meth(*args) # This simply shouldn't fail f.close() diff --git a/Lib/test/test_urllib2_localnet.py b/Lib/test/test_urllib2_localnet.py index 3ae1b3cf22e1fc..77dec0ce713ccb 100644 --- a/Lib/test/test_urllib2_localnet.py +++ b/Lib/test/test_urllib2_localnet.py @@ -306,7 +306,7 @@ def test_basic_auth_success(self): try: self.assertTrue(urllib.request.urlopen(self.server_url)) except urllib.error.HTTPError: - self.fail(f"Basic auth failed for the url: {self.server_url}") + self.fail("Basic auth failed for the url: %s" % self.server_url) def test_basic_auth_httperror(self): ah = urllib.request.HTTPBasicAuthHandler()