Python coverage does not redirect output to a file

Viewed 455

I am trying to run coverage on a Python file of unit tests, WorkTest.py, and forward the output to a file, output.txt.

$ coverage run --branch WorkTest.py > output.txt

But, the output keeps appearing on the screen and there is no output.txt in the folder where I ran this command in. Why does coverage fail to redirect the output to the file?

I have Windows 10, python 3.6.8, coverage 5.1, and command line Git Bash that comes with Git. Thank you.

1 Answers

Check first if the output is not actually in the stderr instead of the stdout:

coverage run --branch WorkTest.py > output.txt 2>&1

The Coverage.py command line usage does mention:

The debug output goes to stderr, unless the COVERAGE_DEBUG_FILE environment variable names a different file, which will be appended to.

Related