diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2017-01-19 22:19:21 -0500 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2017-01-19 22:19:21 -0500 |
commit | e60719206392ed47f28ddeadafa8319be90ae0f0 (patch) | |
tree | 7f929fb710d698eda905da0bd238838244cb8316 /coverage | |
parent | 4d89d792e10218efea93e96ec810ecc45340c2a8 (diff) | |
download | python-coveragepy-git-e60719206392ed47f28ddeadafa8319be90ae0f0.tar.gz |
A better way to deal with StopEverything exceptions
Diffstat (limited to 'coverage')
-rw-r--r-- | coverage/cmdline.py | 4 | ||||
-rw-r--r-- | coverage/misc.py | 18 |
2 files changed, 16 insertions, 6 deletions
diff --git a/coverage/cmdline.py b/coverage/cmdline.py index 9d9d6536..ce929f48 100644 --- a/coverage/cmdline.py +++ b/coverage/cmdline.py @@ -13,7 +13,7 @@ import traceback from coverage import env from coverage.collector import CTracer from coverage.execfile import run_python_file, run_python_module -from coverage.misc import CoverageException, ExceptionDuringRun, NoSource +from coverage.misc import BaseCoverageException, ExceptionDuringRun, NoSource from coverage.debug import info_formatter, info_header @@ -760,7 +760,7 @@ def main(argv=None): # exception. traceback.print_exception(*err.args) status = ERR - except CoverageException as err: + except BaseCoverageException as err: # A controlled error inside coverage.py: print the message to the user. print(err) status = ERR diff --git a/coverage/misc.py b/coverage/misc.py index cb9248d2..d3723e29 100644 --- a/coverage/misc.py +++ b/coverage/misc.py @@ -255,8 +255,13 @@ class SimpleRepr(object): ) -class CoverageException(Exception): - """An exception specific to coverage.py.""" +class BaseCoverageException(Exception): + """The base of all Coverage exceptions.""" + pass + + +class CoverageException(BaseCoverageException): + """A run-of-the-mill exception specific to coverage.py.""" pass @@ -298,6 +303,11 @@ class StopEverything(getattr(unittest, 'SkipTest', Exception)): pass -class IncapablePython(CoverageException, StopEverything): - """An operation is attempted that this version of Python cannot do.""" +class IncapablePython(BaseCoverageException, StopEverything): + """An operation is attempted that this version of Python cannot do. + + This is derived from BaseCoverageException, not CoverageException, so that + it won't get caught by 'except CoverageException'. + + """ pass |