Skip to content
Browse files

Show test coverage report if coverage package is available

  • Loading branch information...
1 parent 8b66863 commit 9c6ce24107b1d782fd4bbc751f8c9899deaa3043 @igorsobreira committed Jan 19, 2012
Showing with 39 additions and 1 deletion.
  1. +15 −0 .coveragerc
  2. +24 −1 tornado/test/runtests.py
View
15 .coveragerc
@@ -0,0 +1,15 @@
+[run]
+branch = true
+source =
+ tornado
+
+omit =
+ tornado/test/*
+ tornado/testing.py
+
+[report]
+ignore_errors = true
+precision = 2
+exclude_lines =
+ # Have to re-enable the standard pragma
+ pragma: no cover
View
25 tornado/test/runtests.py
@@ -1,6 +1,14 @@
#!/usr/bin/env python
import unittest
+try:
+ import coverage
+ use_coverage = True
+except ImportError:
+ use_coverage = False
+ import sys
+ print >> sys.stderr, "Test coverage disabled. To enable install ``coverage`` package"
+
TEST_MODULES = [
'tornado.httputil.doctests',
'tornado.iostream.doctests',
@@ -28,6 +36,21 @@
def all():
return unittest.defaultTestLoader.loadTestsFromNames(TEST_MODULES)
+def run_with_coverage(runtests):
+ cov = coverage.coverage(config_file=True)
+ cov.start()
+ try:
+ runtests()
+ except SystemExit, e:
+ cov.stop()
+ cov.save()
+ cov.report()
+ raise e
+
if __name__ == '__main__':
import tornado.testing
- tornado.testing.main()
+
+ if use_coverage:
+ run_with_coverage(tornado.testing.main)
+ else:
+ tornado.testing.main()

0 comments on commit 9c6ce24

Please sign in to comment.
Something went wrong with that request. Please try again.