Pry - Code Annotation

Many projects contain code that can not be covered by unit tests. Having these portions show up in test coverage statistics is not helpful, so pry provides a way to annotate code to exempt lines from coverage.

Example

def method():
    if True:
        return 1
    #begin nocover
    else:
        return 2
    #end nocover
(examples/project/module/two.py)

Even though the code within the nocover block is unreachable, it does not show up in analysis output, and two.py has 100% coverage:

> 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 %]

If a #begin nocover directive is not matched by an #end nocover directive, it applies to the remainder of the file.

Copyright Nullcube 2008