From c689ec0410d77f35cc14ce18281a4ef278b7de72 Mon Sep 17 00:00:00 2001 From: Stephen Finucane Date: Fri, 18 Nov 2016 14:47:35 +0000 Subject: Read options from tox.ini If coveragerc does not exist, setup.cfg does not exist or does not contain any coverage-related metadata, and no custom config file is provided, fall back to tox.ini. The syntax of tox.ini files is the same as that expected of setup.cfg files, namely: [coverage:{section}] Fixes: #519 --HG-- branch : issue-519 --- coverage/control.py | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'coverage/control.py') diff --git a/coverage/control.py b/coverage/control.py index d9203379..e658ef1b 100644 --- a/coverage/control.py +++ b/coverage/control.py @@ -134,10 +134,8 @@ class Coverage(object): # 1: defaults: self.config = CoverageConfig() - # 2: from the rcfile, .coveragerc or setup.cfg file: + # 2: from the rcfile, .coveragerc, .tox or setup.cfg file: if config_file: - # pylint: disable=redefined-variable-type - did_read_rc = False # Some API users were specifying ".coveragerc" to mean the same as # True, so make it so. if config_file == ".coveragerc": @@ -147,14 +145,22 @@ class Coverage(object): config_file = ".coveragerc" self.config_file = config_file - did_read_rc = self.config.from_file(config_file) + for fname, prefix in [(config_file, ""), + ("setup.cfg", "coverage:"), + ("tox.ini", "coverage:")]: + config_read = self.config.from_file(fname, + section_prefix=prefix) + print('config read?') + print(config_read) + is_config_file = fname == config_file - if not did_read_rc: - if specified_file: + if not config_read and is_config_file and specified_file: raise CoverageException( - "Couldn't read '%s' as a config file" % config_file + "Couldn't read '%s' as a config file" % fname ) - self.config.from_file("setup.cfg", section_prefix="coverage:") + + if config_read: + break # 3: from environment variables: env_data_file = os.environ.get('COVERAGE_FILE') -- cgit v1.2.1