Index: Misc/NEWS =================================================================== --- Misc/NEWS (revision 86636) +++ Misc/NEWS (working copy) @@ -86,6 +86,9 @@ - Issue #10429: IMAP.starttls() stored the capabilities as bytes objects, rather than strings. +- Issue #10470: 'python -m unittest' will now run test discovery by default, + when no extra arguments have been provided. + C-API ----- Index: Doc/library/unittest.rst =================================================================== --- Doc/library/unittest.rst (revision 86636) +++ Doc/library/unittest.rst (working copy) @@ -208,6 +208,12 @@ python -m unittest -v test_module +When executed without arguments:: + + python -m unittest + +The module performs :ref:`unittest-test-discovery`. + For a list of all the command-line options:: python -m unittest -h Index: Lib/unittest/test/test_program.py =================================================================== --- Lib/unittest/test/test_program.py (revision 86636) +++ Lib/unittest/test/test_program.py (working copy) @@ -64,16 +64,25 @@ return self.suiteClass( [self.loadTestsFromTestCase(Test_TestProgram.FooBar)]) + def register_restore_path(self): + """Register a function on .addCleanup that restores sys.path to its + current condition. + """ + orig_sys_path = sys.path[:] + def restore_path(): + sys.path[:] = orig_sys_path + self.addCleanup(restore_path) def test_NonExit(self): + self.register_restore_path() program = unittest.main(exit=False, argv=["foobar"], testRunner=unittest.TextTestRunner(stream=io.StringIO()), testLoader=self.FooBarLoader()) self.assertTrue(hasattr(program, 'result')) - def test_Exit(self): + self.register_restore_path() self.assertRaises( SystemExit, unittest.main, @@ -84,6 +93,7 @@ def test_ExitAsDefault(self): + self.register_restore_path() self.assertRaises( SystemExit, unittest.main, Index: Lib/unittest/main.py =================================================================== --- Lib/unittest/main.py (revision 86636) +++ Lib/unittest/main.py (working copy) @@ -109,7 +109,9 @@ sys.exit(2) def parseArgs(self, argv): - if len(argv) > 1 and argv[1].lower() == 'discover': + # Run test discovery: either 'discover' is the fist argument, or by + # default, when no arguments are specified. + if len(argv) == 1 or (len(argv) > 1 and argv[1].lower() == 'discover'): self._do_discovery(argv[2:]) return