def test_TestRunner_should_have_expected_data_on_test_body_and_teardown_failure( mock_board): class MyTest(TestBase): def test_body(self): raise Exception('Foobar') def teardown(self): raise Exception('Baz') expected_data = [{ 'data': {}, 'order': 0, 'settings': {}, 'tasks': { 'failed': { 'test_body': 'Foobar', 'teardown': 'Baz' }, 'ran': ['setup', 'test_body', 'teardown'] } }] runner = TestRunner(board=mock_board, tests=MyTest(mock_board)) runner.run() assert PlumaOutputMatcher('test_TestRunner.MyTest', expected_data) == runner.data
def test_TestRunner_should_have_expected_data_single_test(mock_board): # This test checks a bit much, but at least ensures data structure matches class MyTest(TestBase): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.settings['hello'] = 'world' def test_body(self): self.save_data({'foo': 'bar'}) def random_func_not_hook(self): pass expected_data = [{ 'data': { 'foo': 'bar' }, 'order': 0, 'settings': { 'hello': 'world' }, 'tasks': { 'failed': {}, 'ran': ['setup', 'test_body', 'teardown'] } }] runner = TestRunner(board=mock_board, tests=MyTest(mock_board)) runner.run() assert PlumaOutputMatcher('test_TestRunner.MyTest', expected_data) == runner.data
def test_TestRunner_should_have_expected_data_on_setup_failure(mock_board): class MyTest(TestBase): def setup(self): raise Exception('Hello') def test_body(self): pass def teardown(self): pass expected_data = [{ 'data': {}, 'order': 0, 'settings': {}, 'tasks': { 'failed': { 'setup': 'Hello' }, 'ran': ['setup'] } }] runner = TestRunner(board=mock_board, tests=MyTest(mock_board)) runner.run() assert PlumaOutputMatcher('test_TestRunner.MyTest', expected_data) == runner.data
def test_TestRunner_should_have_expected_data_multiple_tests_different_class( mock_board): class MyFirstTest(TestBase): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.settings['hello'] = 'world' def test_body(self): self.save_data({'foo': 'bar'}) class MySecondTest(TestBase): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.settings['fizz'] = 'buzz' def setup(self): pass def test_body(self): self.save_data(the_answer=42, the_question='Ask again in ten million years') expected_data = [{ 'data': { 'foo': 'bar' }, 'order': 0, 'settings': { 'hello': 'world' }, 'tasks': { 'failed': {}, 'ran': ['setup', 'test_body', 'teardown'] } }, { 'data': { 'the_answer': 42, 'the_question': 'Ask again in ten million years' }, 'order': 1, 'settings': { 'fizz': 'buzz' }, 'tasks': { 'failed': {}, 'ran': ['setup', 'test_body', 'teardown'] } }] test1 = MyFirstTest(mock_board) test2 = MySecondTest(mock_board) runner = TestRunner(board=mock_board, tests=[test1, test2]) runner.run() assert PlumaOutputMatcher( ['test_TestRunner.MyFirstTest', 'test_TestRunner.MySecondTest'], expected_data) == runner.data