Pry - Coverage

Overview

The examples in this section can be found in the examples/project directory in the pry distribution. From this directory we can run pry with the -s argument to provide a coverage summary:

> pry -s
..
2 tests (pass: 2) - 0.001s

> .
[tot ] [run ] [percent]
-----------------------
[0   ] [0   ] [100.0 %]     __init__.py  
[3   ] [3   ] [100.0 %]     two.py  
[9   ] [4   ] [44.44 %]     one.py  
                            5 [8...11]
-----------------------
[12  ] [7   ] [58.33 %]

As the output shows, the test suite does not completely cover the file one.py - lines 5 and 8 to 11 have not been run. The contents of this file are as follows:

 1 def method():
 2     if True:
 3         return 1
 4     else:
 5         return 2
 6 
 7 def method2():
 8     x = 2
 9     if x:
10         y = 3
11     z = 1
(examples/project/module/one.py)

Line 5 is clearly not covered because it is unreachable. An inspection of the relevant portion of the test suite shows that method2 is never called:

import libpry
import module.one

class One(libpry.AutoTree):
    def test_a(self):
        assert module.one.method() == 1

tests = [
    One()
]
(examples/project/test/test_one.py)

Copyright Nullcube 2008