From: Ezio Melotti <ezio.melotti@gmail.com> Date: Tue, 12 Mar 2013 05:49:12 +0000 (+0200) Subject: #17066: test_robotparser now works with unittest test discovery. Patch by Zachary... X-Git-Tag: v3.3.1rc1~59 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0fb37ea34d260d817520578057ab79dc97f780ff;p=python #17066: test_robotparser now works with unittest test discovery. Patch by Zachary Ware. --- diff --git a/Lib/test/test_robotparser.py b/Lib/test/test_robotparser.py index 178761dd38..8c09e7452c 100644 --- a/Lib/test/test_robotparser.py +++ b/Lib/test/test_robotparser.py @@ -6,7 +6,10 @@ from urllib.request import urlopen from test import support class RobotTestCase(unittest.TestCase): - def __init__(self, index, parser, url, good, agent): + def __init__(self, index=None, parser=None, url=None, good=None, agent=None): + # workaround to make unittest discovery work (see #17066) + if not isinstance(index, int): + return unittest.TestCase.__init__(self) if good: self.str = "RobotTest(%d, good, %s)" % (index, url) @@ -269,10 +272,11 @@ class NetworkTestCase(unittest.TestCase): self.assertTrue( parser.can_fetch("*", "http://www.python.org/robots.txt")) -def test_main(): - support.run_unittest(NetworkTestCase) - support.run_unittest(tests) +def load_tests(loader, suite, pattern): + suite = unittest.makeSuite(NetworkTestCase) + suite.addTest(tests) + return suite if __name__=='__main__': - support.verbose = 1 - test_main() + support.use_resources = ['network'] + unittest.main() diff --git a/Misc/NEWS b/Misc/NEWS index 11ab410ce1..fd10f5ced5 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -662,6 +662,9 @@ Tests - Issue #15539: Added regression tests for Tools/scripts/pindent.py. +- Issue #17066: test_robotparser now works with unittest test discovery. + Patch by Zachary Ware. + - Issue #17334: test_index now works with unittest test discovery. Patch by Zachary Ware.