5

Introduction

A directory containing a test and main python file has been created. Executing a test works:

C:\...>py test/test.py
..
----------------------------------------------------------------------
Ran 2 tests in 0.001s

OK

According to this documentation it is possible to measure code coverage using the command line.

A number of commands has been issued:

C:\...>coverage run --source="C:\path\to\test"
Nothing to do.
Use 'coverage help' for help.

C:\...>coverage run --source "C:\path\to\test\main.py" -m "C:\path\to\test\test.py"
No module named 'C:\path\to\test\test.py'

without success.

Question

Which command needs to be issued in order to measure the code coverage of a Python file using CoveragePy?

1 Answer 1

6

For coverage to capture data, you run the tests with the coverage tool. Something like this:

coverage run py test/test.py

Coverage can be awkward to get set up, but it's incredibly useful -- have fun!

You collect execution data by running your Python program with the run command:

$ coverage run my_program.py arg1 arg2 

(from http://nedbatchelder.com/code/coverage/cmd.html#cmd)

Sign up to request clarification or add additional context in comments.

1 Comment

Running coverage run main.py test.py and subsequently coverage report results in main 2 1 50%. Thank you. I will accept and upvote the answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.