diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0d20b64 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.pyc diff --git a/CoverageTestRunner.py b/CoverageTestRunner.py index a63b9c2..a69c0d2 100644 --- a/CoverageTestRunner.py +++ b/CoverageTestRunner.py @@ -23,6 +23,7 @@ import sys import time import logging +import operator __version__ = '1.11' @@ -258,11 +259,12 @@ def run(self): if result.missing_test_modules: print(len(result.missing_test_modules), "missing test modules") - maxtime = int(os.environ.get('COVERAGE_TEST_RUNNER_MAX_TIME', '10')) + maxtime = float(os.environ.get('COVERAGE_TEST_RUNNER_MAX_TIME', '10')) if end_time - start_time > maxtime: print() print("Slowest tests:") - for secs, test in sorted(result.timings)[-10:]: + timings = sorted(result.timings, key=operator.itemgetter(0)) + for secs, test in timings[-10:]: print(" %5.1f s %s" % (secs, str(test)[:70])) print("Time: %.1f s" % (end_time - start_time)) diff --git a/subdir/foo.py b/subdir/foo.py index 51a5dde..7a23f0f 100644 --- a/subdir/foo.py +++ b/subdir/foo.py @@ -13,4 +13,8 @@ def foo(self, a): time.sleep(0) return False + def slow(self, seconds): + import time + time.sleep(seconds) + foo = Foo() diff --git a/subdir/foo_tests.py b/subdir/foo_tests.py index a8a9740..cdc83bd 100644 --- a/subdir/foo_tests.py +++ b/subdir/foo_tests.py @@ -1,11 +1,19 @@ -import unittest, foo +import unittest +import foo + class FooTests(unittest.TestCase): def testTrue(self): f = foo.Foo() self.failUnlessEqual(f.foo(True), True) - + def testFalse(self): f = foo.Foo() self.failUnlessEqual(f.foo(False), False) + + +class SlowTests(unittest.TestCase): + + def testSlow(self): + foo.Foo().slow(0.11) diff --git a/testrun b/testrun index bf89868..2356af5 100755 --- a/testrun +++ b/testrun @@ -2,4 +2,6 @@ set -e +export COVERAGE_TEST_RUNNER_MAX_TIME=0.1 + python CoverageTestRunner.py subdir --ignore-missing-from=test-excluded