avocado.core.test: Fix problem with unittest compatibility

Introduced with commit d6abdcd4,
avocado tests no longer report correctly to the unittest runner.
The reason is that there is a structure that must be correctly
updated by the run() method (the result instance), that was not
being updated in the new implementation.

Therefore, one possible fix, presented here, is to once again
*not* implement run() at all. this way we avoid messing around
with internal data structures, and when avocado is executed
under nosetests, or the default unittest runner, we get the
expected behavior of the method. The downside is that we have
less perceived integration among both classes.
Signed-off-by: NLucas Meneghel Rodrigues <lmr@redhat.com>
上级 57553554
......@@ -300,17 +300,6 @@ class Test(unittest.TestCase):
"""
pass
def runTest(self):
"""
Actual test payload. Must be implemented by tests.
In case of an existing test suite wrapper, it'll execute the suite,
or perform a series of operations, and based in the results of the
operations decide if the test pass (let the test complete) or fail
(raise a test related exception).
"""
pass
def tearDown(self):
"""
Cleanup stage after the runTest is done.
......@@ -345,11 +334,9 @@ class Test(unittest.TestCase):
'Actual:\n%s\nExpected:\n%s' % (actual, expected))
self.assertEqual(expected, actual, msg)
def run(self, result=None):
def _run_avocado(self):
"""
Run test method, for compatibility with unittest.TestCase.
:result: Unused param, compatibiltiy with :class:`unittest.TestCase`.
Auxiliary method to run_avocado.
"""
testMethod = getattr(self, self._testMethodName)
self.start_logging()
......@@ -437,7 +424,7 @@ class Test(unittest.TestCase):
os.environ['AVOCADO_TEST_OUTPUTDIR'] = self.outputdir
os.environ['AVOCADO_TEST_SYSINFODIR'] = self.sysinfodir
def run_avocado(self, result=None):
def run_avocado(self):
"""
Wraps the run method, for execution inside the avocado runner.
......@@ -446,7 +433,7 @@ class Test(unittest.TestCase):
self._setup_environment_variables()
try:
self.tag_start()
self.run(result)
self._run_avocado()
except exceptions.TestBaseException, detail:
self.status = detail.status
self.fail_class = detail.__class__.__name__
......
......@@ -16,5 +16,11 @@ class SkipOnSetupTest(Test):
"""
self.skip('This should end with SKIP.')
def test_wont_be_executed(self):
"""
This won't get to be executed, given that setUp calls .skip().
"""
pass
if __name__ == "__main__":
main()
......@@ -41,6 +41,12 @@ class _Stream(object):
class JSONResultTest(unittest.TestCase):
def setUp(self):
class SimpleTest(Test):
def runTest(self):
pass
self.tmpfile = tempfile.mkstemp()
self.tmpdir = tempfile.mkdtemp()
args = argparse.Namespace(json_output=self.tmpfile[1])
......@@ -49,7 +55,7 @@ class JSONResultTest(unittest.TestCase):
self.test_result = jsonresult.JSONTestResult(stream, args)
self.test_result.filename = self.tmpfile[1]
self.test_result.start_tests()
self.test1 = Test(job=job.Job(), base_logdir=self.tmpdir)
self.test1 = SimpleTest(job=job.Job(), base_logdir=self.tmpdir)
self.test1.status = 'PASS'
self.test1.time_elapsed = 1.23
......
......@@ -36,26 +36,11 @@ class TestClassTest(unittest.TestCase):
self.assertTrue(variable)
self.whiteboard = 'foo'
class EmptyTest(test.Test):
"""
I don't have runTest() defined!
"""
pass
self.base_logdir = tempfile.mkdtemp(prefix='avocado_test_unittest')
self.tst_instance_pass = AvocadoPass(base_logdir=self.base_logdir)
self.tst_instance_pass.run_avocado()
self.tst_instance_pass_new = AvocadoPass(base_logdir=self.base_logdir)
self.tst_instance_pass_new.run_avocado()
self.tst_instance_empty = EmptyTest(base_logdir=self.base_logdir)
self.tst_instance_empty.run_avocado()
def testRunTest(self):
self.assertEqual(self.tst_instance_empty.runTest(), None)
def testRunAvocado(self):
self.assertEqual(self.tst_instance_empty.status, 'PASS')
def testClassAttributesName(self):
self.assertEqual(self.tst_instance_pass.name, 'AvocadoPass')
......
......@@ -45,13 +45,19 @@ class _Stream(object):
class xUnitSucceedTest(unittest.TestCase):
def setUp(self):
class SimpleTest(Test):
def runTest(self):
pass
self.tmpfile = tempfile.mkstemp()
self.tmpdir = tempfile.mkdtemp()
args = argparse.Namespace()
args.xunit_output = self.tmpfile[1]
self.test_result = xunit.xUnitTestResult(stream=_Stream(), args=args)
self.test_result.start_tests()
self.test1 = Test(job=job.Job(), base_logdir=self.tmpdir)
self.test1 = SimpleTest(job=job.Job(), base_logdir=self.tmpdir)
self.test1.status = 'PASS'
self.test1.time_elapsed = 1.23
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册