diff options
author | Michael Foord <fuzzyman@voidspace.org.uk> | 2010-12-19 03:59:10 +0000 |
---|---|---|
committer | Michael Foord <fuzzyman@voidspace.org.uk> | 2010-12-19 03:59:10 +0000 |
commit | f100dbd6009e18bb1ab14fa6da8732751b1a9add (patch) | |
tree | f4e8500aa979023c5c9b37a7d5ddbdcb6daebc8e /Lib/unittest/main.py | |
parent | b3468f79efa45c8adaf86c0b9b797b9b3d4c12a2 (diff) | |
download | cpython-git-f100dbd6009e18bb1ab14fa6da8732751b1a9add.tar.gz |
Fix minor issue in implementation of issue 10470.
Diffstat (limited to 'Lib/unittest/main.py')
-rw-r--r-- | Lib/unittest/main.py | 70 |
1 files changed, 40 insertions, 30 deletions
diff --git a/Lib/unittest/main.py b/Lib/unittest/main.py index b25d7ac21e..55d4e4be14 100644 --- a/Lib/unittest/main.py +++ b/Lib/unittest/main.py @@ -147,38 +147,48 @@ class TestProgram(object): long_opts = ['help', 'verbose', 'quiet', 'failfast', 'catch', 'buffer'] try: options, args = getopt.getopt(argv[1:], 'hHvqfcb', long_opts) - for opt, value in options: - if opt in ('-h','-H','--help'): - self.usageExit() - if opt in ('-q','--quiet'): - self.verbosity = 0 - if opt in ('-v','--verbose'): - self.verbosity = 2 - if opt in ('-f','--failfast'): - if self.failfast is None: - self.failfast = True - # Should this raise an exception if -f is not valid? - if opt in ('-c','--catch'): - if self.catchbreak is None: - self.catchbreak = True - # Should this raise an exception if -c is not valid? - if opt in ('-b','--buffer'): - if self.buffer is None: - self.buffer = True - # Should this raise an exception if -b is not valid? - if len(args) == 0 and self.defaultTest is None: - # createTests will load tests from self.module - self.testNames = None - elif len(args) > 0: - self.testNames = _convert_names(args) - if __name__ == '__main__': - # to support python -m unittest ... - self.module = None - else: - self.testNames = (self.defaultTest,) - self.createTests() except getopt.error as msg: self.usageExit(msg) + return + + for opt, value in options: + if opt in ('-h','-H','--help'): + self.usageExit() + if opt in ('-q','--quiet'): + self.verbosity = 0 + if opt in ('-v','--verbose'): + self.verbosity = 2 + if opt in ('-f','--failfast'): + if self.failfast is None: + self.failfast = True + # Should this raise an exception if -f is not valid? + if opt in ('-c','--catch'): + if self.catchbreak is None: + self.catchbreak = True + # Should this raise an exception if -c is not valid? + if opt in ('-b','--buffer'): + if self.buffer is None: + self.buffer = True + # Should this raise an exception if -b is not valid? + + if len(args) == 0 and self.module is None: + # this allows "python -m unittest -v" to still work for + # test discovery. This means -c / -b / -v / -f options will + # be handled twice, which is harmless but not ideal. + self._do_discovery(argv[1:]) + return + + if len(args) == 0 and self.defaultTest is None: + # createTests will load tests from self.module + self.testNames = None + elif len(args) > 0: + self.testNames = _convert_names(args) + if __name__ == '__main__': + # to support python -m unittest ... + self.module = None + else: + self.testNames = (self.defaultTest,) + self.createTests() def createTests(self): if self.testNames is None: |