How to use bisect_tests method in stestr

Best Python code snippet using stestr_python

runtests.py

Source:runtests.py Github

copy

Full Screen

...126 test_runner = TestRunner(verbosity=verbosity, interactive=interactive, failfast=failfast)127 failures = test_runner.run_tests(test_labels, extra_tests=extra_tests)128 teardown(state)129 return failures130def bisect_tests(bisection_label, options, test_labels):131 state = setup(int(options.verbosity), test_labels)132 if not test_labels:133 # Get the full list of test labels to use for bisection134 from django.db.models.loading import get_apps135 test_labels = [app.__name__.split('.')[-2] for app in get_apps()]136 print '***** Bisecting test suite:',' '.join(test_labels)137 # Make sure the bisection point isn't in the test list138 # Also remove tests that need to be run in specific combinations139 for label in [bisection_label, 'model_inheritance_same_model_name']:140 try:141 test_labels.remove(label)142 except ValueError:143 pass144 subprocess_args = [sys.executable, __file__, '--settings=%s' % options.settings]145 if options.failfast:146 subprocess_args.append('--failfast')147 if options.verbosity:148 subprocess_args.append('--verbosity=%s' % options.verbosity)149 if not options.interactive:150 subprocess_args.append('--noinput')151 iteration = 1152 while len(test_labels) > 1:153 midpoint = len(test_labels)/2154 test_labels_a = test_labels[:midpoint] + [bisection_label]155 test_labels_b = test_labels[midpoint:] + [bisection_label]156 print '***** Pass %da: Running the first half of the test suite' % iteration157 print '***** Test labels:',' '.join(test_labels_a)158 failures_a = subprocess.call(subprocess_args + test_labels_a)159 print '***** Pass %db: Running the second half of the test suite' % iteration160 print '***** Test labels:',' '.join(test_labels_b)161 print162 failures_b = subprocess.call(subprocess_args + test_labels_b)163 if failures_a and not failures_b:164 print "***** Problem found in first half. Bisecting again..."165 iteration = iteration + 1166 test_labels = test_labels_a[:-1]167 elif failures_b and not failures_a:168 print "***** Problem found in second half. Bisecting again..."169 iteration = iteration + 1170 test_labels = test_labels_b[:-1]171 elif failures_a and failures_b:172 print "***** Multiple sources of failure found"173 break174 else:175 print "***** No source of failure found... try pair execution (--pair)"176 break177 if len(test_labels) == 1:178 print "***** Source of error:",test_labels[0]179 teardown(state)180def paired_tests(paired_test, options, test_labels):181 state = setup(int(options.verbosity), test_labels)182 if not test_labels:183 print ""184 # Get the full list of test labels to use for bisection185 from django.db.models.loading import get_apps186 test_labels = [app.__name__.split('.')[-2] for app in get_apps()]187 print '***** Trying paired execution'188 # Make sure the constant member of the pair isn't in the test list189 # Also remove tests that need to be run in specific combinations190 for label in [paired_test, 'model_inheritance_same_model_name']:191 try:192 test_labels.remove(label)193 except ValueError:194 pass195 subprocess_args = [sys.executable, __file__, '--settings=%s' % options.settings]196 if options.failfast:197 subprocess_args.append('--failfast')198 if options.verbosity:199 subprocess_args.append('--verbosity=%s' % options.verbosity)200 if not options.interactive:201 subprocess_args.append('--noinput')202 for i, label in enumerate(test_labels):203 print '***** %d of %d: Check test pairing with %s' % (i+1, len(test_labels), label)204 failures = subprocess.call(subprocess_args + [label, paired_test])205 if failures:206 print '***** Found problem pair with',label207 return208 print '***** No problem pair found'209 teardown(state)210if __name__ == "__main__":211 from optparse import OptionParser212 usage = "%prog [options] [module module module ...]"213 parser = OptionParser(usage=usage)214 parser.add_option('-v','--verbosity', action='store', dest='verbosity', default='1',215 type='choice', choices=['0', '1', '2', '3'],216 help='Verbosity level; 0=minimal output, 1=normal output, 2=all output')217 parser.add_option('--noinput', action='store_false', dest='interactive', default=True,218 help='Tells Django to NOT prompt the user for input of any kind.')219 parser.add_option('--failfast', action='store_true', dest='failfast', default=False,220 help='Tells Django to stop running the test suite after first failed test.')221 parser.add_option('--settings',222 help='Python path to settings module, e.g. "myproject.settings". If this isn\'t provided, the DJANGO_SETTINGS_MODULE environment variable will be used.')223 parser.add_option('--bisect', action='store', dest='bisect', default=None,224 help="Bisect the test suite to discover a test that causes a test failure when combined with the named test.")225 parser.add_option('--pair', action='store', dest='pair', default=None,226 help="Run the test suite in pairs with the named test to find problem pairs.")227 options, args = parser.parse_args()228 if options.settings:229 os.environ['DJANGO_SETTINGS_MODULE'] = options.settings230 elif "DJANGO_SETTINGS_MODULE" not in os.environ:231 parser.error("DJANGO_SETTINGS_MODULE is not set in the environment. "232 "Set it or use --settings.")233 else:234 options.settings = os.environ['DJANGO_SETTINGS_MODULE']235 if options.bisect:236 bisect_tests(options.bisect, options, args)237 elif options.pair:238 paired_tests(options.pair, options, args)239 else:240 failures = django_tests(int(options.verbosity), options.interactive, options.failfast, args)241 if failures:...

Full Screen

Full Screen

test_bisect_tests.py

Source:test_bisect_tests.py Github

copy

Full Screen

...146 return FakeNoFailing()147 self.repo_mock.get_failing = get_failures148 bisector = bisect_tests.IsolationAnalyzer(149 run, self.conf_mock, self.run_func_mock, self.repo_mock)150 return_code = bisector.bisect_tests(['test_c'])151 expected_issue = [('failing test', 'caused by test'),152 ('test_c', 'unknown - no conflicts')]153 table_mock.assert_called_once_with(expected_issue)154 self.assertEqual(3, return_code)155 @mock.patch('stestr.output.output_table')156 def test_bisect_tests_not_isolated_failure(self, table_mock):157 run = FakeFailedTestRunWithTags()158 self.conf_mock.get_run_command = mock.MagicMock()159 def get_failures(*args, **kwargs):160 return FakeFailingWithTags()161 self.repo_mock.get_failing = get_failures162 bisector = bisect_tests.IsolationAnalyzer(163 run, self.conf_mock, self.run_func_mock, self.repo_mock)164 return_code = bisector.bisect_tests(['test_c'])165 expected_issue = [('failing test', 'caused by test'),166 ('test_c', 'test_a')]167 table_mock.assert_called_once_with(expected_issue)168 self.assertEqual(3, return_code)169 @mock.patch('stestr.output.output_table')170 def test_bisect_tests_not_isolated_multiworker_failures(self, table_mock):171 run = FakeFailedMultiWorkerTestRunWithTags()172 self.conf_mock.get_run_command = mock.MagicMock()173 def get_failures(*args, **kwargs):174 return FakeFailingWithTags()175 self.repo_mock.get_failing = get_failures176 bisector = bisect_tests.IsolationAnalyzer(177 run, self.conf_mock, self.run_func_mock, self.repo_mock)178 return_code = bisector.bisect_tests(['test_b', 'test_c'])179 expected_issue = [('failing test', 'caused by test'),180 ('test_b', 'unknown - no conflicts'),181 ('test_c', 'test_a')]182 table_mock.assert_called_once_with(expected_issue)...

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