mirror of
https://github.com/python/cpython.git
synced 2025-09-17 22:20:23 +00:00
Adds an exit parameter to unittest.main(). If False main no longer
calls sys.exit. Closes issue 3379. Michael Foord
This commit is contained in:
parent
27f204dc29
commit
829f6b8052
4 changed files with 98 additions and 12 deletions
|
@ -1015,7 +1015,7 @@ class TestSuite(object):
|
|||
def __eq__(self, other):
|
||||
if not isinstance(other, self.__class__):
|
||||
return NotImplemented
|
||||
return self._tests == other._tests
|
||||
return list(self) == list(other)
|
||||
|
||||
def __ne__(self, other):
|
||||
return not self == other
|
||||
|
@ -1469,7 +1469,7 @@ Examples:
|
|||
"""
|
||||
def __init__(self, module='__main__', defaultTest=None,
|
||||
argv=None, testRunner=TextTestRunner,
|
||||
testLoader=defaultTestLoader):
|
||||
testLoader=defaultTestLoader, exit=True):
|
||||
if isinstance(module, basestring):
|
||||
self.module = __import__(module)
|
||||
for part in module.split('.')[1:]:
|
||||
|
@ -1478,6 +1478,8 @@ Examples:
|
|||
self.module = module
|
||||
if argv is None:
|
||||
argv = sys.argv
|
||||
|
||||
self.exit = exit
|
||||
self.verbosity = 1
|
||||
self.defaultTest = defaultTest
|
||||
self.testRunner = testRunner
|
||||
|
@ -1529,15 +1531,12 @@ Examples:
|
|||
else:
|
||||
# it is assumed to be a TestRunner instance
|
||||
testRunner = self.testRunner
|
||||
result = testRunner.run(self.test)
|
||||
sys.exit(not result.wasSuccessful())
|
||||
self.result = testRunner.run(self.test)
|
||||
if self.exit:
|
||||
sys.exit(not self.result.wasSuccessful())
|
||||
|
||||
main = TestProgram
|
||||
|
||||
|
||||
##############################################################################
|
||||
# Executing this module from the command line
|
||||
##############################################################################
|
||||
|
||||
if __name__ == "__main__":
|
||||
main(module=None)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue