summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--TODO.txt2
-rw-r--r--coverage/test_helpers.py4
-rw-r--r--tests/test_api.py8
-rw-r--r--tests/test_cmdline.py4
-rw-r--r--tests/test_html.py8
-rw-r--r--tests/test_misc.py2
-rw-r--r--tests/test_process.py5
-rw-r--r--tests/test_summary.py4
8 files changed, 18 insertions, 19 deletions
diff --git a/TODO.txt b/TODO.txt
index 3ff96139..0062dbe6 100644
--- a/TODO.txt
+++ b/TODO.txt
@@ -22,7 +22,7 @@ Key:
- .format() ?
+ try/except/finally
+ with assertRaises
- - addCleanup instead of tearDown
+ + addCleanup instead of tearDown
+ exec statement can look like a function in py2 (since when?)
- runpy ?
+ we can use "except ExcClass as e:"
diff --git a/coverage/test_helpers.py b/coverage/test_helpers.py
index e9ad377a..55a67a0c 100644
--- a/coverage/test_helpers.py
+++ b/coverage/test_helpers.py
@@ -45,7 +45,7 @@ class ModuleAwareMixin(TestCase):
def setUp(self):
super(ModuleAwareMixin, self).setUp()
- # Record sys.modules here so we can restore it in tearDown.
+ # Record sys.modules here so we can restore it in cleanup_modules.
self.old_modules = dict(sys.modules)
self.addCleanup(self.cleanup_modules)
@@ -88,7 +88,7 @@ class EnvironmentAwareMixin(TestCase):
"""Set an environment variable `name` to be `value`.
The environment variable is set, and record is kept that it was set,
- so that `tearDown` can restore its original value.
+ so that `cleanup_environ` can restore its original value.
"""
if name not in self.environ_undos:
diff --git a/tests/test_api.py b/tests/test_api.py
index 00f6dbe8..b0752730 100644
--- a/tests/test_api.py
+++ b/tests/test_api.py
@@ -371,15 +371,13 @@ class UsingModulesMixin(object):
def setUp(self):
super(UsingModulesMixin, self).setUp()
# Parent class saves and restores sys.path, we can just modify it.
- self.old_dir = os.getcwd()
+ old_dir = os.getcwd()
os.chdir(self.nice_file(os.path.dirname(__file__), 'modules'))
+ self.addCleanup(os.chdir, old_dir)
+
sys.path.append(".")
sys.path.append("../moremodules")
- def tearDown(self):
- os.chdir(self.old_dir)
- super(UsingModulesMixin, self).tearDown()
-
class OmitIncludeTestsMixin(UsingModulesMixin):
"""Test methods for coverage methods taking include and omit."""
diff --git a/tests/test_cmdline.py b/tests/test_cmdline.py
index 9ff9bd11..da6e320c 100644
--- a/tests/test_cmdline.py
+++ b/tests/test_cmdline.py
@@ -626,10 +626,10 @@ class CmdMainTest(CoverageTest):
super(CmdMainTest, self).setUp()
self.old_CoverageScript = coverage.cmdline.CoverageScript
coverage.cmdline.CoverageScript = self.CoverageScriptStub
+ self.addCleanup(self.restore_coverage_script)
- def tearDown(self):
+ def restore_coverage_script(self):
coverage.cmdline.CoverageScript = self.old_CoverageScript
- super(CmdMainTest, self).tearDown()
def test_normal(self):
ret = coverage.cmdline.main(['hello'])
diff --git a/tests/test_html.py b/tests/test_html.py
index 7af695de..31b4d876 100644
--- a/tests/test_html.py
+++ b/tests/test_html.py
@@ -63,10 +63,10 @@ class HtmlDeltaTest(HtmlTestHelpers, CoverageTest):
# At least one of our tests monkey-patches the version of coverage,
# so grab it here to restore it later.
self.real_coverage_version = coverage.__version__
+ self.addCleanup(self.restore_coverage_version)
- def tearDown(self):
+ def restore_coverage_version(self):
coverage.__version__ = self.real_coverage_version
- super(HtmlDeltaTest, self).tearDown()
def test_html_created(self):
# Test basic HTML generation: files should be created.
@@ -359,10 +359,10 @@ class HtmlStaticFileTest(CoverageTest):
def setUp(self):
super(HtmlStaticFileTest, self).setUp()
self.original_path = list(coverage.html.STATIC_PATH)
+ self.addCleanup(self.restore_static_path)
- def tearDown(self):
+ def restore_static_path(self):
coverage.html.STATIC_PATH = self.original_path
- super(HtmlStaticFileTest, self).tearDown()
def test_copying_static_files_from_system(self):
# Make a new place for static files.
diff --git a/tests/test_misc.py b/tests/test_misc.py
index d9b0c4e6..152207b5 100644
--- a/tests/test_misc.py
+++ b/tests/test_misc.py
@@ -75,7 +75,7 @@ class SetupPyTest(CoverageTest):
def test_more_metadata(self):
# Let's be sure we pick up our own setup.py
- # CoverageTest.tearDown restores the original sys.path.
+ # CoverageTest restores the original sys.path for us.
sys.path.insert(0, '')
from setup import setup_args
diff --git a/tests/test_process.py b/tests/test_process.py
index 5ab6ba69..4f612748 100644
--- a/tests/test_process.py
+++ b/tests/test_process.py
@@ -738,8 +738,9 @@ class ProcessCoverageMixin(object):
else: # pragma: not covered
raise Exception("Couldn't find a place for the .pth file")
- def tearDown(self):
- super(ProcessCoverageMixin, self).tearDown()
+ self.addCleanup(self.remove_pth_path)
+
+ def remove_pth_path(self):
# Clean up the .pth file we made.
os.remove(self.pth_path)
diff --git a/tests/test_summary.py b/tests/test_summary.py
index 878ae894..c7327f1f 100644
--- a/tests/test_summary.py
+++ b/tests/test_summary.py
@@ -501,8 +501,8 @@ class SummaryTest(CoverageTest):
class SummaryTest2(CoverageTest):
"""Another bunch of summary tests."""
# This class exists because tests naturally clump into classes based on the
- # needs of their setUp and tearDown, rather than the product features they
- # are testing. There's probably a better way to organize these.
+ # needs of their setUp, rather than the product features they are testing.
+ # There's probably a better way to organize these.
run_in_temp_dir = False