summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2021-11-13 16:05:37 -0500
committerNed Batchelder <ned@nedbatchelder.com>2021-11-13 16:05:37 -0500
commit79753a1476a407b4fe1fad69081395c497d53d21 (patch)
tree461d19a7f78ece7cf5cb27b3a6edc9977fcb40e4
parent6a6b60426c3b45d91ab9211c50bea8ecc191e59a (diff)
downloadpython-coveragepy-git-79753a1476a407b4fe1fad69081395c497d53d21.tar.gz
fix: suppress exceptions when finding source= modules. #1203
-rw-r--r--CHANGES.rst8
-rw-r--r--coverage/inorout.py2
-rw-r--r--doc/source.rst2
3 files changed, 11 insertions, 1 deletions
diff --git a/CHANGES.rst b/CHANGES.rst
index 65f0c21a..b811114d 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -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.
@@ -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:
diff --git a/coverage/inorout.py b/coverage/inorout.py
index 174a19dc..87afdaaf 100644
--- a/coverage/inorout.py
+++ b/coverage/inorout.py
@@ -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:
diff --git a/doc/source.rst b/doc/source.rst
index 18eb706c..85a46a33 100644
--- a/doc/source.rst
+++ b/doc/source.rst
@@ -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