How to use mock_test_fail method in toolium

Best Python code snippet using toolium_python

test_jira.py

Source:test_jira.py Github

copy

Full Screen

...138 pass139 config.set('Jira', 'enabled', 'true')140 # Execute method with jira annotation141 with pytest.raises(AssertionError):142 MockTestClass().mock_test_fail()143 # Check jira status144 expected_status = {'TOOLIUM-3': ('TOOLIUM-3', 'Fail', "The test 'test name' has failed: test error", [])}145 assert expected_status == jira.jira_tests_status146def test_jira_annotation_multiple(logger):147 # Configure jira module148 config = DriverWrappersPool.get_default_wrapper().config149 try:150 config.add_section('Jira')151 except Exception:152 pass153 config.set('Jira', 'enabled', 'true')154 # Execute methods with jira annotation155 MockTestClass().mock_test_pass()156 with pytest.raises(AssertionError):157 MockTestClass().mock_test_fail()158 MockTestClass().mock_test_pass_2()159 # Check jira status160 expected_status = {'TOOLIUM-1': ('TOOLIUM-1', 'Pass', None, []),161 'TOOLIUM-3': ('TOOLIUM-3', 'Fail', "The test 'test name' has failed: test error", []),162 'TOOLIUM-2': ('TOOLIUM-2', 'Pass', None, [])}163 assert expected_status == jira.jira_tests_status164def test_jira_disabled(logger):165 # Configure jira module166 config = DriverWrappersPool.get_default_wrapper().config167 try:168 config.add_section('Jira')169 except Exception:170 pass171 config.set('Jira', 'enabled', 'false')172 # Execute method with jira annotation173 MockTestClass().mock_test_pass()174 # Check jira status175 expected_status = {}176 assert expected_status == jira.jira_tests_status177class MockTestClass():178 def get_method_name(self):179 return 'test name'180 @jira.jira(test_key='TOOLIUM-1')181 def mock_test_pass(self):182 pass183 @jira.jira(test_key='TOOLIUM-2')184 def mock_test_pass_2(self):185 pass186 @jira.jira(test_key='TOOLIUM-3')187 def mock_test_fail(self):...

Full Screen

Full Screen

unittest3_backport_test.py

Source:unittest3_backport_test.py Github

copy

Full Screen

1"""Tests for absl.third_party.unittest3_backport."""2from __future__ import absolute_import3from __future__ import division4from __future__ import print_function5import unittest6from absl.testing import absltest7from absl.testing import xml_reporter8import mock9import six10class MockTestResult(xml_reporter._TextAndXMLTestResult):11 def __init__(self):12 super(MockTestResult, self).__init__(six.StringIO(), six.StringIO(),13 'description', False)14 self.subtest_success = []15 self.subtest_failure = []16 def addSubTest(self, test, subtest, err): # pylint: disable=invalid-name17 super(MockTestResult, self).addSubTest(test, subtest, err)18 if six.PY2:19 params = {}20 for param in subtest.params:21 for param_name, param_value in param.items():22 params[param_name] = param_value23 else:24 params = dict(subtest.params)25 if err is not None:26 self.addSubTestFailure(params)27 else:28 self.addSubTestSuccess(params)29 def addSubTestFailure(self, params): # pylint: disable=invalid-name30 self.subtest_failure.append(params)31 def addSubTestSuccess(self, params): # pylint: disable=invalid-name32 self.subtest_success.append(params)33class MockTestResultWithoutSubTest(xml_reporter._TextAndXMLTestResult):34 # hasattr(MockTestResultWithoutSubTest, addSubTest) return False35 def __init__(self):36 super(MockTestResultWithoutSubTest, self).__init__(six.StringIO(),37 six.StringIO(),38 'description',39 False)40 @property41 def addSubTest(self): # pylint: disable=invalid-name42 raise AttributeError43class Unittest3BackportTest(absltest.TestCase):44 def test_subtest_pass(self):45 class Foo(absltest.TestCase):46 def runTest(self):47 for i in [1, 2]:48 with self.subTest(i=i):49 for j in [2, 3]:50 with self.subTest(j=j):51 pass52 result = MockTestResult()53 Foo().run(result)54 expected_success = [{'i': 1, 'j': 2}, {'i': 1, 'j': 3}, {'i': 1},55 {'i': 2, 'j': 2}, {'i': 2, 'j': 3}, {'i': 2}]56 self.assertListEqual(result.subtest_success, expected_success)57 def test_subtest_fail(self):58 class Foo(absltest.TestCase):59 def runTest(self):60 for i in [1, 2]:61 with self.subTest(i=i):62 for j in [2, 3]:63 with self.subTest(j=j):64 if j == 2:65 self.fail('failure')66 result = MockTestResult()67 Foo().run(result)68 # The first layer subtest result is only added to the output when it is a69 # success70 expected_success = [{'i': 1, 'j': 3}, {'i': 2, 'j': 3}]71 expected_failure = [{'i': 1, 'j': 2}, {'i': 2, 'j': 2}]72 self.assertListEqual(expected_success, result.subtest_success)73 self.assertListEqual(expected_failure, result.subtest_failure)74 def test_subtest_expected_failure(self):75 class Foo(absltest.TestCase):76 @unittest.expectedFailure77 def runTest(self):78 for i in [1, 2, 3]:79 with self.subTest(i=i):80 self.assertEqual(i, 2)81 foo = Foo()82 with mock.patch.object(foo, '_addExpectedFailure',83 autospec=True) as mock_subtest_expected_failure:84 result = MockTestResult()85 foo.run(result)86 self.assertEqual(mock_subtest_expected_failure.call_count, 1)87 def test_subtest_unexpected_success(self):88 class Foo(absltest.TestCase):89 @unittest.expectedFailure90 def runTest(self):91 for i in [1, 2, 3]:92 with self.subTest(i=i):93 self.assertEqual(i, i)94 foo = Foo()95 with mock.patch.object(foo, '_addUnexpectedSuccess',96 autospec=True) as mock_subtest_unexpected_success:97 result = MockTestResult()98 foo.run(result)99 self.assertEqual(mock_subtest_unexpected_success.call_count, 1)100 def test_subtest_fail_fast(self):101 # Ensure failfast works with subtest102 class Foo(absltest.TestCase):103 def runTest(self):104 with self.subTest(i=1):105 self.fail('failure')106 with self.subTest(i=2):107 self.fail('failure')108 self.fail('failure')109 result = MockTestResult()110 result.failfast = True111 Foo().run(result)112 expected_failure = [{'i': 1}]113 self.assertListEqual(expected_failure, result.subtest_failure)114 def test_subtest_skip(self):115 # When a test case is skipped, addSubTest should not be called116 class Foo(absltest.TestCase):117 @unittest.skip('no reason')118 def runTest(self):119 for i in [1, 2, 3]:120 with self.subTest(i=i):121 self.assertEqual(i, i)122 foo = Foo()123 result = MockTestResult()124 with mock.patch.object(foo, '_addSkip', autospec=True) as mock_test_skip:125 with mock.patch.object(result, 'addSubTestSuccess',126 autospec=True) as mock_subtest_success:127 foo.run(result)128 self.assertEqual(mock_test_skip.call_count, 1)129 self.assertEqual(mock_subtest_success.call_count, 0)130 @mock.patch.object(MockTestResultWithoutSubTest, 'addFailure', autospec=True)131 def test_subtest_legacy(self, mock_test_fail):132 # When the result object does not have addSubTest method,133 # text execution stops after the first subtest failure.134 class Foo(absltest.TestCase):135 def runTest(self):136 for i in [1, 2, 3]:137 with self.subTest(i=i):138 if i == 1:139 self.fail('failure')140 for j in [2, 3]:141 with self.subTest(j=j):142 if i * j == 6:143 raise RuntimeError('raised by Foo.test')144 result = MockTestResultWithoutSubTest()145 Foo().run(result)146 self.assertEqual(mock_test_fail.call_count, 1)147if __name__ == '__main__':...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run toolium automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful