Best Python code snippet using stestr_python
run.py
Source:run.py  
...221                    return 0222                # spurious-failure -> cause.223                test_conflicts = {}224                for spurious_failure in spurious_failures:225                    candidate_causes = self._prior_tests(226                        latest_run, spurious_failure)227                    bottom = 0228                    top = len(candidate_causes)229                    width = top - bottom230                    while width:231                        check_width = int(ceil(width / 2.0))232                        cmd = testcommand.get_run_command(233                            candidate_causes[bottom:bottom + check_width]234                            + [spurious_failure],235                            self.ui.arguments['testargs'])236                        self._run_tests(cmd)237                        # check that the test we're probing still failed - still238                        # awkward.239                        found_fail = []240                        def find_fail(test_dict):241                            if test_dict['id'] == spurious_failure:242                                found_fail.append(True)243                        checker = testtools.StreamToDict(find_fail)244                        checker.startTestRun()245                        try:246                            repo.get_failing().get_test().run(checker)247                        finally:248                            checker.stopTestRun()249                        if found_fail:250                            # Our conflict is in bottom - clamp the range down.251                            top = bottom + check_width252                            if width == 1:253                                # found the cause254                                test_conflicts[255                                    spurious_failure] = candidate_causes[bottom]256                                width = 0257                            else:258                                width = top - bottom259                        else:260                            # Conflict in the range we did not run: discard bottom.261                            bottom = bottom + check_width262                            if width == 1:263                                # there will be no more to check, so we didn't264                                # reproduce the failure.265                                width = 0266                            else:267                                width = top - bottom268                    if spurious_failure not in test_conflicts:269                        # Could not determine cause270                        test_conflicts[spurious_failure] = 'unknown - no conflicts'271                if test_conflicts:272                    table = [('failing test', 'caused by test')]273                    for failure, causes in test_conflicts.items():274                        table.append((failure, causes))275                    self.ui.output_table(table)276                    return 3277                return 0278        finally:279            testcommand.cleanUp()280    def _prior_tests(self, run, failing_id):281        """Calculate what tests from the test run run ran before test_id.282        Tests that ran in a different worker are not included in the result.283        """284        if not getattr(self, '_worker_to_test', False):285            # TODO: switch to route codes?286            case = run.get_test()287            # Use None if there is no worker-N tag288            # If there are multiple, map them all.289            # (worker-N -> [testid, ...])290            worker_to_test = {}291            # (testid -> [workerN, ...])292            test_to_worker = {}293            def map_test(test_dict):294                tags = test_dict['tags']...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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
