summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2019-11-03 10:17:40 -0500
committerNed Batchelder <ned@nedbatchelder.com>2019-11-03 21:27:42 -0500
commit25311c6caabed2f13da991dae52352c3c896a3e9 (patch)
tree347736ed68e204502d110bea0a8192ed3a2ffc5e
parenta44e6e48abfdab8f5a7e457ae1e481005f7bdbe5 (diff)
downloadpython-coveragepy-git-25311c6caabed2f13da991dae52352c3c896a3e9.tar.gz
Expand environment variables in any part of a TOML config
-rw-r--r--coverage/tomlconfig.py11
-rw-r--r--tests/test_config.py3
2 files changed, 6 insertions, 8 deletions
diff --git a/coverage/tomlconfig.py b/coverage/tomlconfig.py
index b6499ec4..144b13ca 100644
--- a/coverage/tomlconfig.py
+++ b/coverage/tomlconfig.py
@@ -8,7 +8,7 @@ import os
import re
from coverage import env
-from coverage.backward import configparser, path_types, string_class, toml
+from coverage.backward import configparser, path_types, toml
from coverage.misc import CoverageException, substitute_variables
@@ -41,7 +41,9 @@ class TomlConfigParser:
for filename in filenames:
try:
with io.open(filename, encoding='utf-8') as fp:
- self._data.append(toml.load(fp))
+ toml_data = fp.read()
+ toml_data = substitute_variables(toml_data, os.environ)
+ self._data.append(toml.loads(toml_data))
except IOError:
continue
except toml.TomlDecodeError as err:
@@ -101,8 +103,6 @@ class TomlConfigParser:
value = section[option]
except KeyError:
continue
- if isinstance(value, string_class):
- value = substitute_variables(value, os.environ)
return value
if not found_section:
raise configparser.NoSectionError(section)
@@ -124,9 +124,6 @@ class TomlConfigParser:
'Option {!r} in section {!r} is not a list: {!r}'
.format(option, section, values)
)
- for i, value in enumerate(values):
- if isinstance(value, string_class):
- values[i] = substitute_variables(value, os.environ)
return values
def getregexlist(self, section, option):
diff --git a/tests/test_config.py b/tests/test_config.py
index 49574241..3bd2fd2b 100644
--- a/tests/test_config.py
+++ b/tests/test_config.py
@@ -229,7 +229,7 @@ class ConfigTest(CoverageTest):
self.make_file("pyproject.toml", """\
[tool.coverage.run]
data_file = "$DATA_FILE.fooey"
- branch = true
+ branch = $BRANCH
[tool.coverage.report]
exclude_lines = [
"the_$$one",
@@ -239,6 +239,7 @@ class ConfigTest(CoverageTest):
"huh$${X}what",
]
""")
+ self.set_environ("BRANCH", "true")
self.set_environ("DATA_FILE", "hello-world")
self.set_environ("THING", "ZZZ")
cov = coverage.Coverage()