coveragepy
coveragepy copied to clipboard
Fix globbing of filenames that contain special glob characters
When specifying a coverage filename using the COVERAGE_FILE
environment variable, special characters are not handled correctly. I use that facility to set the name of the coverage file to match the name of the test that I am running in pytest, so that I can associate the coverage with the specific test that generated that coverage. Some test names contain brackets, so the name of the test might be exampletest[b-a]
, and I transform that name into .coverage.exampletest[b-a]
and then run
COVERAGE_FILE=.coverage.exampletest[b-a] pytest --cov "exampletest[b-a]"
Which results in the error:
re.error: bad character range b-a at position 5
Any special characters in a filename specified for creating a new file should be escaped before globbing for similar filenames.