summaryrefslogtreecommitdiff
path: root/coverage
diff options
context:
space:
mode:
Diffstat (limited to 'coverage')
-rw-r--r--coverage/config.py9
-rw-r--r--coverage/control.py32
2 files changed, 23 insertions, 18 deletions
diff --git a/coverage/config.py b/coverage/config.py
index 7287e963..3b873579 100644
--- a/coverage/config.py
+++ b/coverage/config.py
@@ -248,7 +248,7 @@ class CoverageConfig:
setattr(self, k, v)
@contract(filename=str)
- def from_file(self, filename, our_file):
+ def from_file(self, filename, warn, our_file):
"""Read configuration from a .rc file.
`filename` is a file name to read.
@@ -297,7 +297,7 @@ class CoverageConfig:
real_section = cp.has_section(section)
if real_section:
for unknown in set(cp.options(section)) - options:
- raise CoverageException(
+ warn(
"Unrecognized option '[{}] {}=' in config file {}".format(
real_section, unknown, filename
)
@@ -517,12 +517,13 @@ def config_files_to_try(config_file):
return files_to_try
-def read_coverage_config(config_file, **kwargs):
+def read_coverage_config(config_file, warn, **kwargs):
"""Read the coverage.py configuration.
Arguments:
config_file: a boolean or string, see the `Coverage` class for the
tricky details.
+ warn: a function to issue warnings.
all others: keyword arguments from the `Coverage` class, used for
setting values in the configuration.
@@ -541,7 +542,7 @@ def read_coverage_config(config_file, **kwargs):
files_to_try = config_files_to_try(config_file)
for fname, our_file, specified_file in files_to_try:
- config_read = config.from_file(fname, our_file=our_file)
+ config_read = config.from_file(fname, warn, our_file=our_file)
if config_read:
break
if specified_file:
diff --git a/coverage/control.py b/coverage/control.py
index e1eb9add..c45b1245 100644
--- a/coverage/control.py
+++ b/coverage/control.py
@@ -192,15 +192,7 @@ class Coverage:
if data_file is _DEFAULT_DATAFILE:
data_file = None
- # Build our configuration from a number of sources.
- self.config = read_coverage_config(
- config_file=config_file,
- data_file=data_file, cover_pylib=cover_pylib, timid=timid,
- branch=branch, parallel=bool_or_none(data_suffix),
- source=source, source_pkgs=source_pkgs, run_omit=omit, run_include=include, debug=debug,
- report_omit=omit, report_include=include,
- concurrency=concurrency, context=context,
- )
+ self.config = None
# This is injectable by tests.
self._debug_file = None
@@ -235,6 +227,16 @@ class Coverage:
# Should we write the debug output?
self._should_write_debug = True
+ # Build our configuration from a number of sources.
+ self.config = read_coverage_config(
+ config_file=config_file, warn=self._warn,
+ data_file=data_file, cover_pylib=cover_pylib, timid=timid,
+ branch=branch, parallel=bool_or_none(data_suffix),
+ source=source, source_pkgs=source_pkgs, run_omit=omit, run_include=include, debug=debug,
+ report_omit=omit, report_include=include,
+ concurrency=concurrency, context=context,
+ )
+
# If we have sub-process measurement happening automatically, then we
# want any explicit creation of a Coverage object to mean, this process
# is already coverage-aware, so don't auto-measure it. By now, the
@@ -352,16 +354,18 @@ class Coverage:
"""
if self._no_warn_slugs is None:
- self._no_warn_slugs = list(self.config.disable_warnings)
+ if self.config is not None:
+ self._no_warn_slugs = list(self.config.disable_warnings)
- if slug in self._no_warn_slugs:
- # Don't issue the warning
- return
+ if self._no_warn_slugs is not None:
+ if slug in self._no_warn_slugs:
+ # Don't issue the warning
+ return
self._warnings.append(msg)
if slug:
msg = f"{msg} ({slug})"
- if self._debug.should('pid'):
+ if self._debug is not None and self._debug.should('pid'):
msg = f"[{os.getpid()}] {msg}"
warnings.warn(msg, category=CoverageWarning, stacklevel=2)