Skip to content

Commit

Permalink
fix: suppress exceptions when finding source= modules. #1203
Browse files Browse the repository at this point in the history
  • Loading branch information
nedbat committed Nov 13, 2021
1 parent 6a6b604 commit 79753a1
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
8 changes: 8 additions & 0 deletions CHANGES.rst
Expand Up @@ -22,6 +22,12 @@ This list is detailed and covers changes in each pre-release version.
Unreleased
----------

- Fix: A module specified as the ``source`` setting is imported during startup,
before the user program imports it. This could cause problems if the rest of
the program isn't ready yet. For example, `issue 1203`_ describes a Django
setting that is accessed before settings have been configured. Now that
early import is wrapped in a try/except so the error doesn't stop execution.

- Fix: A colon in a decorator expression would cause an exclusion to end too
early, preventing the exclusion of the decorated function. This is now fixed.

Expand All @@ -31,6 +37,8 @@ Unreleased
- Debug: The `coverage debug data` command will now sniff out combinable data
files, and report on all of them.

.. _issue 1203: https://github.com/nedbat/coveragepy/issues/1203


.. _changes_612:

Expand Down
2 changes: 1 addition & 1 deletion coverage/inorout.py
Expand Up @@ -120,7 +120,7 @@ def file_and_path_for_module(modulename):
path = []
try:
spec = importlib.util.find_spec(modulename)
except ImportError:
except Exception:
pass
else:
if spec is not None:
Expand Down
2 changes: 2 additions & 0 deletions doc/source.rst
Expand Up @@ -46,6 +46,8 @@ scratch files written by text editors). Files that do not end with ``.py``,
isn't a problem, but could cause trouble if a module has side-effects at
import time.

Exceptions during the early import are suppressed and ignored.

You can further fine-tune coverage.py's attention with the ``--include`` and
``--omit`` switches (or ``[run] include`` and ``[run] omit`` configuration
values). ``--include`` is a list of file name patterns. If specified, only
Expand Down

0 comments on commit 79753a1

Please sign in to comment.