diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2010-02-28 13:11:21 -0500 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2010-02-28 13:11:21 -0500 |
commit | 99d5e7491a3b73a44de306b9735c26e4d63c0f20 (patch) | |
tree | bb91eacce9be27ffb843231697ed230c5299a53c /coverage/cmdline.py | |
parent | 6dda195647a19a94a88c299ef4521626ebd044e1 (diff) | |
download | python-coveragepy-99d5e7491a3b73a44de306b9735c26e4d63c0f20.tar.gz |
If the user's code calls sys.exit(), honor the request and exit with that status. Fixes issue #50.
Diffstat (limited to 'coverage/cmdline.py')
-rw-r--r-- | coverage/cmdline.py | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/coverage/cmdline.py b/coverage/cmdline.py index c938368..9e15074 100644 --- a/coverage/cmdline.py +++ b/coverage/cmdline.py @@ -589,25 +589,30 @@ Coverage.py, version %(__version__)s. %(__url__)s """ -def main(): +def main(argv=None): """The main entrypoint to Coverage. This is installed as the script entrypoint. """ + if argv is None: + argv = sys.argv[1:] try: - status = CoverageScript().command_line(sys.argv[1:]) + status = CoverageScript().command_line(argv) except ExceptionDuringRun: # An exception was caught while running the product code. The # sys.exc_info() return tuple is packed into an ExceptionDuringRun - # exception. Note that the Python interpreter doesn't print SystemExit - # tracebacks, so it's important that we don't also. + # exception. _, err, _ = sys.exc_info() - if not isinstance(err.args[1], SystemExit): - traceback.print_exception(*err.args) + traceback.print_exception(*err.args) status = ERR except CoverageException: + # A controlled error inside coverage.py: print the message to the user. _, err, _ = sys.exc_info() print(err) status = ERR + except SystemExit: + # The user called `sys.exit()`. Exit with their status code. + _, err, _ = sys.exc_info() + status = err.args[0] return status |