diff --git a/mobly/test_runner.py b/mobly/test_runner.py index b32f5b0f..15c44d30 100644 --- a/mobly/test_runner.py +++ b/mobly/test_runner.py @@ -79,7 +79,7 @@ def main(argv=None): runner.run() ok = runner.results.is_all_pass and ok except signals.TestAbortAll: - pass + ok = False except Exception: logging.exception('Exception when executing %s.', config.testbed_name) ok = False diff --git a/tests/mobly/test_runner_test.py b/tests/mobly/test_runner_test.py index 0bdf5126..401f2ed7 100755 --- a/tests/mobly/test_runner_test.py +++ b/tests/mobly/test_runner_test.py @@ -335,6 +335,25 @@ def test_main_parse_args(self, mock_test_runner, mock_config, mock_find_test): test_runner.main(['-c', 'some/path/foo.yaml', '-b', 'hello']) mock_config.assert_called_with('some/path/foo.yaml', None) + @mock.patch( + 'mobly.test_runner._find_test_class', + return_value=type('SampleTest', (), {}), + ) + @mock.patch( + 'mobly.test_runner.config_parser.load_test_config_file', + return_value=[config_parser.TestRunConfig()], + ) + @mock.patch('mobly.test_runner.TestRunner') + @mock.patch('sys.exit') + def test_main_with_abort_all( + self, mock_exit, mock_test_runner_class, mock_config, mock_find_test + ): + mock_runner = mock.MagicMock() + mock_runner.run.side_effect = signals.TestAbortAll('Aborting all tests.') + mock_test_runner_class.return_value = mock_runner + test_runner.main(['-c', 'some/path/foo.yaml']) + mock_exit.assert_called_once_with(1) + @mock.patch( 'mobly.test_runner._find_test_class', return_value=integration_test.IntegrationTest,