diff options
-rw-r--r-- | coverage/test_helpers.py | 13 | ||||
-rw-r--r-- | tests/test_coverage.py | 6 | ||||
-rw-r--r-- | tests/test_data.py | 2 |
3 files changed, 14 insertions, 7 deletions
diff --git a/coverage/test_helpers.py b/coverage/test_helpers.py index 55a67a0c..3f058b1d 100644 --- a/coverage/test_helpers.py +++ b/coverage/test_helpers.py @@ -147,8 +147,15 @@ class TempDirMixin(SysPathAwareMixin, ModuleAwareMixin, TestCase): """ # Our own setting: most of these tests run in their own temp directory. + # Set this to False in your subclass if you don't want a temp directory + # created. run_in_temp_dir = True + # Set this if you aren't creating any files with make_file, but still want + # the temp directory. This will stop the test behavior checker from + # complaining. + no_files_in_temp_dir = False + def setUp(self): super(TempDirMixin, self).setUp() @@ -165,8 +172,8 @@ class TempDirMixin(SysPathAwareMixin, ModuleAwareMixin, TestCase): class_behavior = self.class_behavior() class_behavior.tests += 1 - class_behavior.test_method_made_any_files = False class_behavior.temp_dir = self.run_in_temp_dir + class_behavior.no_files_ok = self.no_files_in_temp_dir self.addCleanup(self.check_behavior) @@ -239,6 +246,7 @@ class TempDirMixin(SysPathAwareMixin, ModuleAwareMixin, TestCase): self.tests = 0 self.skipped = 0 self.temp_dir = True + self.no_files_ok = False self.tests_making_files = 0 self.test_method_made_any_files = False @@ -252,7 +260,8 @@ class TempDirMixin(SysPathAwareMixin, ModuleAwareMixin, TestCase): if behavior.tests <= behavior.skipped: bad = "" elif behavior.temp_dir and behavior.tests_making_files == 0: - bad = "Inefficient" + if not behavior.no_files_ok: + bad = "Inefficient" elif not behavior.temp_dir and behavior.tests_making_files > 0: bad = "Unsafe" else: diff --git a/tests/test_coverage.py b/tests/test_coverage.py index 35c7c25c..3de381f1 100644 --- a/tests/test_coverage.py +++ b/tests/test_coverage.py @@ -1672,7 +1672,7 @@ class ReportingTest(CoverageTest): # We don't make any temp files, but we need an empty directory to run the # tests in. - run_in_temp_dir = True + no_files_in_temp_dir = True def test_no_data_to_report_on_annotate(self): # Reporting with no data produces a nice message and no output dir. @@ -1680,10 +1680,6 @@ class ReportingTest(CoverageTest): self.command_line("annotate -d ann") self.assert_doesnt_exist("ann") - # CoverageTest will yell at us for using a temp directory with no files - # made. Instead of adding a way to shut it up, just make a file. - self.make_file("touch.txt", "") - def test_no_data_to_report_on_html(self): # Reporting with no data produces a nice message and no output dir. with self.assertRaisesRegex(CoverageException, "No data to report."): diff --git a/tests/test_data.py b/tests/test_data.py index e2f8150b..776f7b59 100644 --- a/tests/test_data.py +++ b/tests/test_data.py @@ -165,6 +165,8 @@ class DataTest(DataTestHelpers, CoverageTest): class DataTestInTempDir(DataTestHelpers, CoverageTest): """Test cases for coverage.data.""" + no_files_in_temp_dir = True + def test_combining_from_different_directories(self): covdata1 = CoverageData() covdata1.add_line_data(DATA_1) |