From 5a8eb35f1c9fdb2f5954cd986a3ac61c02c24b62 Mon Sep 17 00:00:00 2001 From: Cleber Rosa Date: Thu, 1 Oct 2015 11:40:31 -0300 Subject: [PATCH] Test Loader: add test for multiple classes support in a single file There's no real reason why a single Python file can not hold multiple test classes, each one with its own tests. This test adds a simple Python test file with two classes, each one with its own test, and expects the loader to find two instrumented tests. Signed-off-by: Cleber Rosa --- selftests/functional/test_loader.py | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/selftests/functional/test_loader.py b/selftests/functional/test_loader.py index 88ce4eaf..9c2a8fd0 100644 --- a/selftests/functional/test_loader.py +++ b/selftests/functional/test_loader.py @@ -49,6 +49,25 @@ if __name__ == "__main__": """ +AVOCADO_TEST_MULTIPLE_CLASSES = """#!/usr/bin/python +import time + +from avocado import Test +from avocado import main + +class First(Test): + def test(self): + pass + +class Second(Test): + def test(self): + pass + +if __name__ == "__main__": + main() +""" + + AVOCADO_TEST_BUGGY = """#!/usr/bin/python from avocado import Test from avocado import main @@ -86,14 +105,14 @@ class LoaderTestFunctional(unittest.TestCase): os.chdir(basedir) self.tmpdir = tempfile.mkdtemp(prefix='avocado_' + __name__) - def _test(self, name, content, exp_str, mode=0664): + def _test(self, name, content, exp_str, mode=0664, count=1): test_script = script.TemporaryScript(name, content, 'avocado_loader_test', mode=mode) test_script.save() cmd_line = ('./scripts/avocado list -V %s' % test_script.path) result = process.run(cmd_line) - self.assertIn('%s: 1' % exp_str, result.stdout) + self.assertIn('%s: %s' % (exp_str, count), result.stdout) test_script.remove() def test_simple(self): @@ -126,6 +145,10 @@ class LoaderTestFunctional(unittest.TestCase): "eleven seconds.")) self.assertIn('INSTRUMENTED: 2', result.stdout) + def test_multiple_class(self): + self._test('multipleclasses.py', AVOCADO_TEST_MULTIPLE_CLASSES, + 'INSTRUMENTED', 0664, 2) + def test_buggy_exec(self): self._test('buggytest.py', AVOCADO_TEST_BUGGY, 'SIMPLE', 0775) -- GitLab