Describe the bug
TomlConfigParser fails to handle environment variables whose value is a JSON-encoded string.
To Reproduce
How can we reproduce the problem? Please be specific. Don't link to a failing CI job. Answer the questions below:
- What version of Python are you using?
3.10.2
- What version of coverage.py shows the problem? The output of
coverage debug sys is helpful. 6.2
- What versions of what packages do you have installed? The output of
pip freeze is helpful.
tomli==2.0.0
pytest==6.2.5
pytest-cov==3.0.0
- What code shows the problem? Give us a specific commit of a specific repo that we can check out. If you've already worked around the problem, please provide a commit before that fix.
See https://github.com/stevenhoelscher/coveragepy-repro for reproduction of the bug.
- What commands did you run?
Expected behavior
When running pytest with pytest-cov (which relies on coveragepy under the hood), another tool's pyproject.toml should not affect coveragepy's ability to parse the configuration file.
Additional context
As you can see in this example, I try to add another tool's configuration to my pyproject.toml. But the substitute_variables function ends up interpolating the environment variable and invalidating the configuration prior to parsing:
'[[tool.docker.env_vars]]\nname = "foo"\nvalue = "\\"{"foo": "bar"}\\""\n\n[tool.pytest.ini_options]\ntestpaths = "src/tests"\naddopts = "--cov=src"\n\n[tool.coverage.run]\nomit = ["src/tests/*"]\n'
>>> import tomli
>>> s = '[[tool.docker.env_vars]]\nname = "foo"\nvalue = "\\"{"foo": "bar"}\\""\n\n[tool.pytest.ini_options]\ntestpaths = "src/tests"\naddopts = "--cov=src"\n\n[tool.coverage.run]\nomit = ["src/tests/*"]\n'
>>> tomli.loads(s)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/developer/code/coveragepy-repro/.venv/lib/python3.10/site-packages/tomli/_parser.py", line 116, in loads
raise suffixed_err(
tomli.TOMLDecodeError: Expected newline or end of document after a statement (at line 3, column 14)
Describe the bug
TomlConfigParserfails to handle environment variables whose value is a JSON-encoded string.To Reproduce
How can we reproduce the problem? Please be specific. Don't link to a failing CI job. Answer the questions below:
3.10.2coverage debug sysis helpful.6.2pip freezeis helpful.See https://github.com/stevenhoelscher/coveragepy-repro for reproduction of the bug.
Expected behavior
When running
pytestwithpytest-cov(which relies oncoveragepyunder the hood), another tool'spyproject.tomlshould not affectcoveragepy's ability to parse the configuration file.Additional context
As you can see in this example, I try to add another tool's configuration to my
pyproject.toml. But thesubstitute_variablesfunction ends up interpolating the environment variable and invalidating the configuration prior to parsing: