Best Python code snippet using Kiwi_python
unittest_checker_variables.py
Source:unittest_checker_variables.py  
...35        node = astroid.extract_node('__all__ = []')36        node.value.elts.append(astroid.Const('test'))37        root = node.root()38        with self.assertNoMessages():39            self.checker.visit_module(root)40            self.checker.leave_module(root)41    def test_redefined_builtin_ignored(self):42        node = astroid.parse('''43        from future.builtins import open44        ''')45        with self.assertNoMessages():46            self.checker.visit_module(node)47    @set_config(redefining_builtins_modules=('os',))48    def test_redefined_builtin_custom_modules(self):49        node = astroid.parse('''50        from os import open51        ''')52        with self.assertNoMessages():53            self.checker.visit_module(node)54    @set_config(redefining_builtins_modules=('os',))55    def test_redefined_builtin_modname_not_ignored(self):56        node = astroid.parse('''57        from future.builtins import open58        ''')59        with self.assertAddsMessages(60                Message('redefined-builtin', node=node.body[0], args='open')):61            self.checker.visit_module(node)62    @set_config(redefining_builtins_modules=('os',))63    def test_redefined_builtin_in_function(self):64        node = astroid.extract_node('''65        def test():66            from os import open67        ''')68        with self.assertNoMessages():69            self.checker.visit_module(node.root())70            self.checker.visit_functiondef(node)71class TestVariablesCheckerWithTearDown(CheckerTestCase):72    CHECKER_CLASS = variables.VariablesChecker73    def setup_method(self):74        super(TestVariablesCheckerWithTearDown, self).setup_method()75        self._to_consume_backup = self.checker._to_consume76        self.checker._to_consume = []77    def teardown_method(self, method):78        self.checker._to_consume = self._to_consume_backup79    @set_config(callbacks=('callback_', '_callback'))80    def test_custom_callback_string(self):81        """ Test the --calbacks option works. """82        node = astroid.extract_node("""83        def callback_one(abc):84             ''' should not emit unused-argument. '''85        """)86        with self.assertNoMessages():87            self.checker.visit_functiondef(node)88            self.checker.leave_functiondef(node)89        node = astroid.extract_node("""90        def two_callback(abc, defg):91             ''' should not emit unused-argument. '''92        """)93        with self.assertNoMessages():94            self.checker.visit_functiondef(node)95            self.checker.leave_functiondef(node)96        node = astroid.extract_node("""97        def normal_func(abc):98             ''' should emit unused-argument. '''99        """)100        with self.assertAddsMessages(101                Message('unused-argument', node=node['abc'], args='abc')):102            self.checker.visit_functiondef(node)103            self.checker.leave_functiondef(node)104        node = astroid.extract_node("""105        def cb_func(abc):106             ''' Previous callbacks are overridden. '''107        """)108        with self.assertAddsMessages(109                Message('unused-argument', node=node['abc'], args='abc')):110            self.checker.visit_functiondef(node)111            self.checker.leave_functiondef(node)112    @set_config(redefining_builtins_modules=('os',))113    def test_redefined_builtin_modname_not_ignored(self):114        node = astroid.parse('''115        from future.builtins import open116        ''')117        with self.assertAddsMessages(118                Message('redefined-builtin', node=node.body[0], args='open')):119            self.checker.visit_module(node)120    @set_config(redefining_builtins_modules=('os',))121    def test_redefined_builtin_in_function(self):122        node = astroid.extract_node('''123        def test():124            from os import open125        ''')126        with self.assertNoMessages():127            self.checker.visit_module(node.root())128            self.checker.visit_functiondef(node)129    def test_import_as_underscore(self):130        node = astroid.parse('''131        import math as _132        ''')133        with self.assertNoMessages():134            self.walk(node)135class TestMissingSubmodule(CheckerTestCase):136    CHECKER_CLASS = variables.VariablesChecker137    def test_package_all(self):138        regr_data = os.path.join(os.path.dirname(os.path.abspath(__file__)),139                                 'regrtest_data')140        sys.path.insert(0, regr_data)141        try:..._loader.py
Source:_loader.py  
...41        coverage_context.start()42        imported_modules = tuple(43            importlib.import_module(name) for name in names)44        for imported_module in imported_modules:45            self.visit_module(imported_module)46        for imported_module in imported_modules:47            try:48                package_paths = imported_module.__path__49            except AttributeError:50                continue51            self.walk_packages(package_paths)52        coverage_context.stop()53        coverage_context.save()54        return self.suite55    def walk_packages(self, package_paths):56        """Walks over the packages, dispatching `visit_module` calls.57    Args:58      package_paths (list): A list of paths over which to walk through modules59        along.60    """61        for importer, module_name, is_package in (62                pkgutil.walk_packages(package_paths)):63            module = importer.find_module(module_name).load_module(module_name)64            self.visit_module(module)65    def visit_module(self, module):66        """Visits the module, adding discovered tests to the test suite.67    Args:68      module (module): Module to match against self.module_matcher; if matched69        it has its tests loaded via self.loader into self.suite.70    """71        if self.module_matcher.match(module.__name__):72            module_suite = self.loader.loadTestsFromModule(module)73            self.suite.addTest(module_suite)74def iterate_suite_cases(suite):75    """Generator over all unittest.TestCases in a unittest.TestSuite.76  Args:77    suite (unittest.TestSuite): Suite to iterate over in the generator.78  Returns:79    generator: A generator over all unittest.TestCases in `suite`....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!!
