summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2015-08-18 07:38:54 -0400
committerNed Batchelder <ned@nedbatchelder.com>2015-08-18 07:38:54 -0400
commit83a248c2a0564562c294c822a96bf7a38aca4e42 (patch)
tree27a579f1841783b8501d7cb3fc546d89a3ea33dc
parent17864e90d64308912feab0c3015a8def716ccbfc (diff)
downloadpython-coveragepy-git-83a248c2a0564562c294c822a96bf7a38aca4e42.tar.gz
Make FarmTestCase work as with cleanups and as a nose test function
-rw-r--r--tests/test_farm.py46
1 files changed, 29 insertions, 17 deletions
diff --git a/tests/test_farm.py b/tests/test_farm.py
index c14426f0..fbb97bed 100644
--- a/tests/test_farm.py
+++ b/tests/test_farm.py
@@ -50,6 +50,10 @@ class FarmTestCase(ModuleAwareMixin, SysPathAwareMixin, unittest.TestCase):
has options to allow various uses of the test cases (normal execution,
cleaning-only, or run and leave the results for debugging).
+ This class is a unittest.TestCase so that we can use behavior-modifying
+ mixins, but it's only useful as a nose test function. Yes, this is
+ confusing.
+
"""
# We don't want test runners finding this and instantiating it themselves.
@@ -70,7 +74,31 @@ class FarmTestCase(ModuleAwareMixin, SysPathAwareMixin, unittest.TestCase):
self.dont_clean = dont_clean
self.ok = True
+ def setUp(self):
+ """Test set up, run by nose before __call__."""
+ super(FarmTestCase, self).setUp()
+ # Modules should be importable from the current directory.
+ sys.path.insert(0, '')
+
+ def tearDown(self):
+ """Test tear down, run by nose after __call__."""
+ # Make sure the test is cleaned up, unless we never want to, or if the
+ # test failed.
+ if not self.dont_clean and self.ok: # pragma: part covered
+ self.clean_only = True
+ self()
+
+ super(FarmTestCase, self).tearDown()
+
+ # This object will be run by nose via the __call__ method, and nose
+ # doesn't do cleanups in that case. Do them now.
+ self.doCleanups()
+
def runTest(self):
+ """Here to make unittest.TestCase happy, but will never be invoked."""
+ raise Exception("runTest isn't used in this class!")
+
+ def __call__(self):
"""Execute the test from the run.py file."""
if _TEST_NAME_FILE: # pragma: debugging
with open(_TEST_NAME_FILE, "w") as f:
@@ -100,26 +128,10 @@ class FarmTestCase(ModuleAwareMixin, SysPathAwareMixin, unittest.TestCase):
"""Run as a full test case, with setUp and tearDown."""
self.setUp()
try:
- self.runTest()
+ self()
finally:
self.tearDown()
- def setUp(self):
- """Test set up, run by nose before runTest."""
- super(FarmTestCase, self).setUp()
- # Modules should be importable from the current directory.
- sys.path.insert(0, '')
-
- def tearDown(self):
- """Test tear down, run by nose after runTest."""
- # Make sure the test is cleaned up, unless we never want to, or if the
- # test failed.
- if not self.dont_clean and self.ok: # pragma: part covered
- self.clean_only = True
- self.runTest()
-
- super(FarmTestCase, self).tearDown()
-
# Functions usable inside farm run.py files