diff options
author | Ned Batchelder <nedbat@gmail.com> | 2015-08-01 12:53:22 -0400 |
---|---|---|
committer | Ned Batchelder <nedbat@gmail.com> | 2015-08-01 12:53:22 -0400 |
commit | 162bab174bf05323e75e247411b8c86e49420415 (patch) | |
tree | 94f28318f3267dc16a7b8bb1f597d8fb52033bee /coverage/test_helpers.py | |
parent | 78a0ad5a6b4668dc9f1807d7bfb431d263b7b071 (diff) | |
parent | 9559181fa49011bc94e51c967010e2cb49714d15 (diff) | |
download | python-coveragepy-162bab174bf05323e75e247411b8c86e49420415.tar.gz |
Merged in traff/coverage.py (pull request #50)
Look for __main__ module if coverage is being run for directory #252
Diffstat (limited to 'coverage/test_helpers.py')
-rw-r--r-- | coverage/test_helpers.py | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/coverage/test_helpers.py b/coverage/test_helpers.py index 55a67a0..3ddb48b 100644 --- a/coverage/test_helpers.py +++ b/coverage/test_helpers.py @@ -1,3 +1,6 @@ +# Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0 +# For details: https://bitbucket.org/ned/coveragepy/src/default/NOTICE.txt + """Mixin classes to help make good tests.""" import atexit @@ -147,8 +150,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 +175,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 +249,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 @@ -249,14 +260,14 @@ class TempDirMixin(SysPathAwareMixin, ModuleAwareMixin, TestCase): def report_on_class_behavior(cls): """Called at process exit to report on class behavior.""" for test_class, behavior in cls.class_behaviors.items(): + bad = "" 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: - bad = "" if bad: if behavior.temp_dir: |