image_test: switch to @unittest.expectedFailure
The only point of the Forgiving/NonForgiving is so that forgiving tests
don't halt execution prematurely relative to non-forgiving tests, and so
the final exit status only reflects the non-forgiving tests.
The unittest module already provides an attribute that does this for us:
@unittest.expectedFailure. Any tests marked with this will not halt the
overall execution and won't affect the exit status. Replace our custom
infrastructure with this one attribute to simplify things greatly w/out
losing any functionality.
BUG=chromium:775932
TEST=test_image & unittests still pass
Change-Id: I4a1a789e928d43e86605f3f40169d2e14e166b73
Reviewed-on: https://chromium-review.googlesource.com/726894
Commit-Ready: Mike Frysinger <vapier@chromium.org>
Tested-by: Mike Frysinger <vapier@chromium.org>
Reviewed-by: Jorge Lucangeli Obes <jorgelo@chromium.org>
diff --git a/scripts/test_image_unittest.py b/scripts/test_image_unittest.py
index 86eb8af..d03b93e 100644
--- a/scripts/test_image_unittest.py
+++ b/scripts/test_image_unittest.py
@@ -73,7 +73,7 @@
def testChdir(self):
"""Verify the CWD is in a temp directory."""
- class CwdTest(image_test_lib.NonForgivingImageTestCase):
+ class CwdTest(image_test_lib.ImageTestCase):
"""A dummy test class to verify current working directory."""
_expected_dir = None
@@ -91,7 +91,7 @@
suite = image_test_lib.ImageTestSuite()
suite.addTest(test)
self.PatchObject(unittest.TestLoader, 'loadTestsFromName', autospec=True,
- return_value=[suite])
+ return_value=suite)
# Set up the expected directory.
expected_dir = os.path.join(self.tempdir, 'my-subdir')
@@ -104,44 +104,10 @@
self.assertEqual(0, test_image.main(argv))
self.assertEqual('/tmp', os.getcwd())
- def _testForgiveness(self, forgiveness, expected_result):
-
- class ForgivenessTest(image_test_lib.ImageTestCase):
- """A dummy test that is sometime forgiving, sometime not.
-
- Its only test (testFail) always fail.
- """
-
- _forgiving = True
-
- def SetForgiving(self, value):
- self._forgiving = value
-
- def IsForgiving(self):
- return self._forgiving
-
- def testFail(self):
- self.fail()
-
- test = ForgivenessTest('testFail')
- test.SetForgiving(forgiveness)
- suite = image_test_lib.ImageTestSuite()
- suite.addTest(test)
- self.PatchObject(unittest.TestLoader, 'loadTestsFromName', autospec=True,
- return_value=[suite])
- argv = [self.tempdir]
- self.assertEqual(expected_result, test_image.main(argv))
-
- def testForgiving(self):
- self._testForgiveness(True, 0)
-
- def testNonForgiving(self):
- self._testForgiveness(False, 1)
-
def testBoardAndDirectory(self):
"""Verify that "--board", "--test_results_root" are passed to the tests."""
- class AttributeTest(image_test_lib.ForgivingImageTestCase):
+ class AttributeTest(image_test_lib.ImageTestCase):
"""Dummy test class to hold board and directory."""
def testOkay(self):
@@ -151,7 +117,7 @@
suite = image_test_lib.ImageTestSuite()
suite.addTest(test)
self.PatchObject(unittest.TestLoader, 'loadTestsFromName', autospec=True,
- return_value=[suite])
+ return_value=suite)
argv = [
'--board',
'my-board',