How to use runnable_test_methods method in Testify

Best Python code snippet using Testify_python

test_runner.py

Source:test_runner.py Github

copy

Full Screen

...108 # We allow our plugins to mutate the test case prior to execution109 for plugin_mod in self.plugin_modules:110 if hasattr(plugin_mod, "prepare_test_case"):111 plugin_mod.prepare_test_case(self.options, test_case)112 if not any(test_case.runnable_test_methods()):113 continue114 def failure_counter(result_dict):115 if not result_dict['success']:116 self.failure_count += 1117 for reporter in self.test_reporters:118 test_case.register_callback(test_case.EVENT_ON_RUN_TEST_METHOD, reporter.test_start)119 test_case.register_callback(test_case.EVENT_ON_COMPLETE_TEST_METHOD, reporter.test_complete)120 test_case.register_callback(test_case.EVENT_ON_RUN_CLASS_SETUP_METHOD, reporter.class_setup_start)121 test_case.register_callback(test_case.EVENT_ON_COMPLETE_CLASS_SETUP_METHOD, reporter.class_setup_complete)122 test_case.register_callback(test_case.EVENT_ON_RUN_CLASS_TEARDOWN_METHOD, reporter.class_teardown_start)123 test_case.register_callback(124 test_case.EVENT_ON_COMPLETE_CLASS_TEARDOWN_METHOD,125 reporter.class_teardown_complete,126 )127 test_case.register_callback(test_case.EVENT_ON_RUN_TEST_CASE, reporter.test_case_start)128 test_case.register_callback(test_case.EVENT_ON_COMPLETE_TEST_CASE, reporter.test_case_complete)129 test_case.register_callback(test_case.EVENT_ON_COMPLETE_TEST_METHOD, failure_counter)130 # Now we wrap our test case like an onion. Each plugin given the opportunity to wrap it.131 runnable = test_case.run132 for plugin_mod in self.plugin_modules:133 if hasattr(plugin_mod, "run_test_case"):134 runnable = functools.partial(plugin_mod.run_test_case, self.options, test_case, runnable)135 # And we finally execute our finely wrapped test case136 runnable()137 except exceptions.DiscoveryError as exc:138 for reporter in self.test_reporters:139 reporter.test_discovery_failure(exc)140 return exit.DISCOVERY_FAILED141 except exceptions.Interruption:142 # handle interruption so we can cancel in the middle of a run143 # but still get a testing summary.144 pass145 report = [reporter.report() for reporter in self.test_reporters]146 if all(report):147 return exit.OK148 else:149 return exit.TESTS_FAILED150 def list_suites(self):151 """List the suites represented by this TestRunner's tests."""152 suites = defaultdict(list)153 for test_instance in self.discover():154 for test_method in test_instance.runnable_test_methods():155 for suite_name in test_instance.suites(test_method):156 suites[suite_name].append(test_method)157 return {suite_name: "%d tests" % len(suite_members) for suite_name, suite_members in suites.items()}158 def get_tests_for_suite(self, selected_suite_name):159 """Gets the test list for the suite"""160 for test_instance in self.discover():161 for test_method in test_instance.runnable_test_methods():162 if not selected_suite_name or TestCase.in_suite(test_method, selected_suite_name):163 yield test_method164 def list_tests(self, format, selected_suite_name=None):165 """Lists all tests, optionally scoped to a single suite."""166 for test in self.get_tests_for_suite(selected_suite_name):167 name = self.get_test_method_name(test)168 if format == 'txt':169 print(name)170 elif format == 'json':171 testcase = test.__self__172 print(json.dumps(173 dict(174 test=name,175 suites=sorted(testcase.suites(test)),...

Full Screen

Full Screen

test_runner_test.py

Source:test_runner_test.py Github

copy

Full Screen

1import imp2import mock3from testify import assert_equal4from testify import setup5from testify import setup_teardown6from testify import test_case7from testify import test_runner8from .test_runner_subdir.inheriting_class import InheritingClass9prepared = False10running = False11def prepare_test_case(options, test_case):12 global prepared13 prepared = True14def run_test_case(options, test_case, runnable):15 global running16 running = True17 try:18 return runnable()19 finally:20 running = False21def add_testcase_info(test_case, runner):22 test_case.__testattr__ = True23class TestTestRunnerGetTestMethodName(test_case.TestCase):24 def test_method_from_other_module_reports_class_module(self):25 ret = test_runner.TestRunner.get_test_method_name(26 InheritingClass().test_foo,27 )28 assert_equal(29 ret,30 '{} {}.{}'.format(31 InheritingClass.__module__,32 InheritingClass.__name__,33 InheritingClass.test_foo.__name__,34 ),35 )36class PluginTestCase(test_case.TestCase):37 """Verify plugin support38 This is pretty complex and deserves some amount of explanation.39 What we're doing here is creating a module object on the fly (our plugin) and a40 test case class so we can call runner directly and verify the right parts get called.41 If you have a failure in here the stack is going to look crazy because we are a test case, being called by42 a test running, which is building and running ANOTHER test runner to execute ANOTHER test case. Cheers.43 """44 @setup45 def build_module(self):46 self.our_module = imp.new_module("our_module")47 setattr(self.our_module, "prepare_test_case", prepare_test_case)48 setattr(self.our_module, "run_test_case", run_test_case)49 setattr(self.our_module, "add_testcase_info", add_testcase_info)50 @setup51 def build_test_case(self):52 self.ran_test = False53 class DummyTestCase(test_case.TestCase):54 def test(self_):55 self.ran_test = True56 assert self.our_module.prepared57 assert self.our_module.running58 assert self.__testattr__59 self.dummy_test_class = DummyTestCase60 def test_plugin_run(self):61 runner = test_runner.TestRunner(self.dummy_test_class, plugin_modules=[self.our_module])62 assert runner.run() == 063 assert self.ran_test64 assert not running65 assert prepared66class TestTestRunnerGetTestsForSuite(test_case.TestCase):67 @setup_teardown68 def mock_out_things(self):69 mock_returned_test = mock.Mock()70 self.mock_test_method = mock.Mock()71 mock_returned_test.runnable_test_methods.return_value = [72 self.mock_test_method,73 ]74 with mock.patch.object(75 test_runner.TestRunner,76 'discover',77 autospec=True,78 return_value=[mock_returned_test],79 ) as self.discover_mock:80 with mock.patch.object(81 test_case.TestCase,82 'in_suite',83 ) as self.in_suite_mock:84 yield85 def test_get_tests_for_suite_in_suite(self):86 self.in_suite_mock.return_value = True87 instance = test_runner.TestRunner(mock.sentinel.test_class)88 ret = instance.get_tests_for_suite(mock.sentinel.selected_suite_name)89 assert_equal(list(ret), [self.mock_test_method])90 def test_get_tests_for_suite_not_in_suite(self):91 self.in_suite_mock.return_value = False92 instance = test_runner.TestRunner(mock.sentinel.test_class)93 ret = instance.get_tests_for_suite(mock.sentinel.selected_suite_name)...

Full Screen

Full Screen

test_suites_test.py

Source:test_suites_test.py Github

copy

Full Screen

...8 Checking https://github.com/Yelp/Testify/issues/53"""9 # If we set suites_require=['super'], then only the superclass should have a method to run.10 super_instance = SuperTestCase(suites_require={'super'})11 sub_instance = SubTestCase(suites_require={'super'})12 assert_equal(list(super_instance.runnable_test_methods()), [super_instance.test_thing])13 assert_equal(list(sub_instance.runnable_test_methods()), [sub_instance.test_thing])14 # Conversely, if we set suites_require=['sub'], then only the subclass should have a method to run.15 super_instance = SuperTestCase(suites_require={'sub'})16 sub_instance = SubTestCase(suites_require={'sub'})17 assert_equal(list(super_instance.runnable_test_methods()), [])18 assert_equal(list(sub_instance.runnable_test_methods()), [sub_instance.test_thing])19 def test_suite_decorator_overrides_parent(self):20 """Check that the @suite decorator overrides any @suite on the overridden (parent class) method."""21 super_instance = SuperDecoratedTestCase()22 sub_instance = SubDecoratedTestCase()23 assert_equal(super_instance.test_thing._suites, {'super'})24 assert_equal(sub_instance.test_thing._suites, {'sub'})25@suite('example')26class ExampleTestCase(TestCase):27 pass28class SuperTestCase(ExampleTestCase):29 _suites = ['super']30 def test_thing(self):31 pass32class SubTestCase(SuperTestCase):33 _suites = ['sub']34class SuperDecoratedTestCase(ExampleTestCase):35 @suite('super')36 def test_thing(self):37 pass38class SubDecoratedTestCase(SuperDecoratedTestCase):39 @suite('sub')40 def test_thing(self):41 pass42class ListSuitesMixin(object):43 """Test that we pick up the correct suites when using --list-suites."""44 # applied to test_foo, test_disabled, test_also.., test_not.., and test_list..45 _suites = ['example', 'class-level-suite']46 def __init__(self, **kwargs):47 super(ListSuitesMixin, self).__init__(**kwargs)48 # add a dynamic test to guard against49 # https://github.com/Yelp/Testify/issues/8550 test = (lambda self: True).__get__(self, type(self))51 setattr(self, 'test_foo', test)52 @suite('disabled', 'crazy', conditions=True)53 def test_disabled(self):54 True55 @suite('disabled', reason='blah')56 def test_also_disabled(self):57 True58 @suite('not-applied', conditions=False)59 def test_not_disabled(self):60 True61 @suite('assertion')62 def test_list_suites(self):63 # for suites affecting all of this class's tests64 num_tests = len(list(self.runnable_test_methods()))65 test_runner = TestRunner(type(self))66 assert_equal(sorted(test_runner.list_suites().items()), [67 ('assertion', '1 tests'),68 ('class-level-suite', '%d tests' % num_tests),69 ('crazy', '1 tests'),70 ('disabled', '2 tests'),71 ('example', '%d tests' % num_tests),72 ('module-level', '%d tests' % num_tests),73 ])74class ListSuitesTestCase(ExampleTestCase, ListSuitesMixin):75 """Test that suites are correctly applied to Testify TestCases."""76 pass77class ListSuitesUnittestCase(unittest.TestCase, ListSuitesMixin):78 """Test that suites are correctly applied to UnitTests."""...

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 Testify 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