diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2012-11-29 23:10:06 -0500 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2012-11-29 23:10:06 -0500 |
commit | 8600bdfd07e069e5f6b78631b14320cb49ee8457 (patch) | |
tree | c9157a7dc5ca5b92a3262c45903c490fb8de3997 /test/coveragetest.py | |
parent | f8d10e6d49a0d34e98cd45a4b0a3c230bdcadda3 (diff) | |
download | python-coveragepy-git-8600bdfd07e069e5f6b78631b14320cb49ee8457.tar.gz |
Refactor a bunch of tests to isolate the recursive coverage calls.
Diffstat (limited to 'test/coveragetest.py')
-rw-r--r-- | test/coveragetest.py | 26 |
1 files changed, 19 insertions, 7 deletions
diff --git a/test/coveragetest.py b/test/coveragetest.py index 4ae399cc..39ec4f56 100644 --- a/test/coveragetest.py +++ b/test/coveragetest.py @@ -212,6 +212,24 @@ class CoverageTest(TestCase): f.close() return mod + def start_import_stop(self, cov, modname): + """Start coverage, import a file, then stop coverage. + + `cov` is started and stopped, with an `import_local_file` of + `modname` in the middle. + + The imported module is returned. + + """ + cov.start() + try: # pragma: recursive coverage + # Import the python file, executing it. + mod = self.import_local_file(modname) + finally: # pragma: recursive coverage + # Stop Coverage. + cov.stop() + return mod + def get_module_name(self): """Return the module name to use for this test run.""" # We append self.n because otherwise two calls in one test will use the @@ -304,14 +322,8 @@ class CoverageTest(TestCase): cov.exclude(exc) for par in partials or []: cov.exclude(par, which='partial') - cov.start() - try: # pragma: recursive coverage - # Import the python file, executing it. - mod = self.import_local_file(modname) - finally: # pragma: recursive coverage - # Stop Coverage. - cov.stop() + mod = self.start_import_stop(cov, modname) # Clean up our side effects del sys.modules[modname] |