Visitar URL original
fix: read config files that start with a UTF-8 byte order mark by SwastikTripathi · Pull Request #2388 · coveragepy/coveragepy · GitHub
Skip to content

fix: read config files that start with a UTF-8 byte order mark - #2388

Merged
nedbat merged 3 commits into
coveragepy:mainfrom
SwastikTripathi:fix/config-bom
Nov 12, 2026
Merged

nedbat merged 3 commits into
coveragepy:mainfrom
SwastikTripathi:fix/config-bom

Conversation

@SwastikTripathi

Copy link
Copy Markdown
Contributor

A config file saved as "UTF-8 with BOM" (Notepad's default on older Windows, and an option in VS Code and other editors) can't be read at all:

$ coverage run m.py          # .coveragerc, setup.cfg or tox.ini starts with a BOM
File contains no section headers.
file: '.coveragerc', line: 1
'[run]\n'

$ coverage run m.py          # pyproject.toml starts with a BOM
Couldn't read config file pyproject.toml: Invalid statement (at line 1, column 1)

Both readers open the file with encoding="utf-8", which keeps the BOM as a  character at the start of the text, and neither configparser nor tomllib skips it. This switches both to utf-8-sig, which drops a leading BOM and otherwise reads the same as utf-8.

test_config_file_with_bom covers .coveragerc, setup.cfg, tox.ini and pyproject.toml; all four fail before the change and pass after it. tests/test_config.py passes. I also ran test_api.py, test_cmdline.py and test_process.py: the only failures are two test_pth_and_source_work_together cases that fail the same way on master here.

@nedbat
nedbat merged commit 33a1cd3 into coveragepy:main Nov 12, 2026
76 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants