diff options
author | Lucas Abel <22837557+uael@users.noreply.github.com> | 2023-04-18 22:09:50 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-18 22:09:50 -0700 |
commit | 8693d1812c7cb3b3c19933970a55c1babb1bf78a (patch) | |
tree | 71eb749c950c10cc648a0a84685e913a754f83cb | |
parent | 8bec7e3f63a5b9c2ca1afc51b6460517445f5c1e (diff) | |
download | mobly-8693d1812c7cb3b3c19933970a55c1babb1bf78a.tar.gz |
Fix the print test list logic in `test_runner` (#878)
-rw-r--r-- | mobly/test_runner.py | 13 | ||||
-rwxr-xr-x | tests/mobly/test_runner_test.py | 11 |
2 files changed, 14 insertions, 10 deletions
diff --git a/mobly/test_runner.py b/mobly/test_runner.py index 624f056..529035f 100644 --- a/mobly/test_runner.py +++ b/mobly/test_runner.py @@ -170,12 +170,19 @@ def _print_test_names(test_class): cls = test_class(config_parser.TestRunConfig()) test_names = [] try: - cls.setup_generated_tests() - test_names = cls.get_existing_test_names() + # Executes pre-setup procedures, this is required since it might + # generate test methods that we want to return as well. + cls._pre_run() + if cls.tests: + # Specified by run list in class. + test_names = list(cls.tests) + else: + # No test method specified by user, list all in test class. + test_names = cls.get_existing_test_names() except Exception: logging.exception('Failed to retrieve generated tests.') finally: - cls._controller_manager.unregister_controllers() + cls._clean_up() print('==========> %s <==========' % cls.TAG) for name in test_names: print(name) diff --git a/tests/mobly/test_runner_test.py b/tests/mobly/test_runner_test.py index efddc4c..0343e0d 100755 --- a/tests/mobly/test_runner_test.py +++ b/tests/mobly/test_runner_test.py @@ -374,20 +374,17 @@ class TestRunnerTest(unittest.TestCase): mock_cls_instance = mock.MagicMock() mock_test_class.return_value = mock_cls_instance test_runner._print_test_names(mock_test_class) - mock_cls_instance.setup_generated_tests.assert_called_once() - mock_cls_instance.get_existing_test_names.assert_called_once() - mock_cls_instance._controller_manager.unregister_controllers.assert_called_once( - ) + mock_cls_instance._pre_run.assert_called_once() + mock_cls_instance._clean_up.assert_called_once() def test_print_test_names_with_exception(self): mock_test_class = mock.MagicMock() mock_cls_instance = mock.MagicMock() mock_test_class.return_value = mock_cls_instance test_runner._print_test_names(mock_test_class) - mock_cls_instance.setup_generated_tests.side_effect = Exception( + mock_cls_instance._pre_run.side_effect = Exception( 'Something went wrong.') - mock_cls_instance._controller_manager.unregister_controllers.assert_called_once( - ) + mock_cls_instance._clean_up.assert_called_once() if __name__ == "__main__": |