Search code examples
pythoncode-coverage

code coverage python from external libraries


Currently am trying to implement an automation testing tool for python projects, however I figure out a problem would like to ask if it is possible to collect the code coverage from external libraries using Coverage module?, as far as I know the coverage module report only the code coverage within the project.

example:

test_code.py


import random


def test_rand()

  assert random.randint(0,10) == 5
 

in this case how can I collect code coverage from random module ?


Solution

  • coverage run --help includes these lines:

      -L, --pylib           Measure coverage even inside the Python installed
                            library, which isn't done by default.