Esempio n. 1
0
    def visit_Call(self, node: ast.Call) -> None:
        if get_qualname(node.func) in _PATCH_NAMES:
            # attributes are (target, new, ...)
            self._check_patch_call(node, 1)

        if get_qualname(node.func) in _PATCH_OBJECT_NAMES:
            # attributes are (target, attribute, new, ...)
            self._check_patch_call(node, 2)
Esempio n. 2
0
    def _check_fixture_addfinalizer(self, node: AnyFunctionDef) -> None:
        """Checks for PT021."""
        if 'request' not in get_all_argument_names(node.args):
            return

        for child in walk_without_nested_functions(node):  # pragma: no branch
            if (isinstance(child, ast.Call)
                    and get_qualname(child.func) == 'request.addfinalizer'):
                self.error_from_node(FixtureFinalizerCallback, child)
                return
Esempio n. 3
0
    def _check_raises_call(self, node: ast.Call) -> None:
        """
        Checks for violations regarding `pytest.raises` call args (PT010 and PT011).
        """
        args = get_simple_call_args(node)
        exception = args.get_argument('expected_exception', position=0)
        if not exception:
            self.error_from_node(RaisesWithoutException, node)
            return

        exception_name = get_qualname(exception)
        if exception_name not in self.config.raises_require_match_for:
            return
        match = args.get_argument('match')
        if match is None or is_none(match) or is_empty_string(match):
            self.error_from_node(RaisesWithoutMatch, node, exception=exception_name)