summaryrefslogtreecommitdiff
path: root/test/coverage_coverage.py
blob: f2a47f78ee4036c03ddc3dc3518db969c0b481f8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# Coverage-test Coverage itself.

import coverage
import os, sys

cov = coverage.coverage()
cov.erase()
cov.start()

# Re-import coverage to get it coverage tested!  I don't understand all the
# mechanics here, but if I don't carry over the imported modules (in covmods),
# then things go haywire (os == None eventually).
covmods = {}
covdir = os.path.split(coverage.__file__)
for name, mod in sys.modules.items():
    if name.startswith('coverage'):
        if hasattr(mod, '__file__') and mod.__file__.startswith(covdir):
            covmods[name] = mod
            del sys.modules[name]
import coverage
sys.modules.update(covmods)

# Run nosetests, with the arguments from our command line.
import nose
nose.run(sys.argv[1:])

cov.stop()
cov.save()  # TODO: This is needed to get group_collected_data called.

cov.exclude("#pragma: no cover")
cov.exclude("def __repr__")
cov.exclude("if __name__ == .__main__.:")

cov.html_report(directory='htmlcov', ignore_errors=True)