diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_api.py | 8 | ||||
-rw-r--r-- | tests/test_cmdline.py | 4 | ||||
-rw-r--r-- | tests/test_html.py | 8 | ||||
-rw-r--r-- | tests/test_misc.py | 2 | ||||
-rw-r--r-- | tests/test_process.py | 5 | ||||
-rw-r--r-- | tests/test_summary.py | 4 |
6 files changed, 15 insertions, 16 deletions
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 |