예제 #1
0
    def _check_mark_parentheses(
        self, mark_decorator: Union[ast.Call, ast.Attribute]
    ) -> None:
        """Checks for PT023."""

        if not isinstance(mark_decorator, ast.Call):
            if self.config.mark_parentheses:
                self.error_from_node(
                    IncorrectMarkParenthesesStyle,
                    mark_decorator,
                    mark_name=get_mark_name(mark_decorator),
                    expected_parens='()',
                    actual_parens='',
                )
            return

        if (
            not self.config.mark_parentheses
            and not mark_decorator.args
            and not mark_decorator.keywords
        ):
            self.error_from_node(
                IncorrectMarkParenthesesStyle,
                mark_decorator,
                mark_name=get_mark_name(mark_decorator.func),
                expected_parens='',
                actual_parens='()',
            )
예제 #2
0
 def _check_fixture_unnecessary_marks(self, node: AnyFunctionDef) -> None:
     """Checks for PT024."""
     marks = get_mark_decorators(node)
     for mark in marks:
         if get_mark_name(mark) == 'asyncio':
             self.error_from_node(UnnecessaryAsyncioMarkOnFixture, mark)
             return
예제 #3
0
    def _check_useless_usefixtures(
        self, mark_decorator: Union[ast.Call, ast.Attribute]
    ) -> None:
        """Checks for PT026."""

        if get_mark_name(mark_decorator) != 'usefixtures':
            return

        has_parameters = isinstance(mark_decorator, ast.Call) and bool(
            mark_decorator.args or mark_decorator.keywords
        )
        if not has_parameters:
            self.error_from_node(UseFixturesWithoutParameters, mark_decorator)
예제 #4
0
 def _check_fixture_marks(self, node: AnyFunctionDef) -> None:
     """Checks for PT024, PT025."""
     reported_errors = set()
     marks = get_mark_decorators(node)
     for mark in marks:
         mark_name = get_mark_name(mark)
         if (mark_name == 'asyncio' and UnnecessaryAsyncioMarkOnFixture
                 not in reported_errors):
             self.error_from_node(UnnecessaryAsyncioMarkOnFixture, mark)
             reported_errors.add(UnnecessaryAsyncioMarkOnFixture)
         if (mark_name == 'usefixtures'
                 and ErroneousUseFixturesOnFixture not in reported_errors):
             self.error_from_node(ErroneousUseFixturesOnFixture, mark)
             reported_errors.add(ErroneousUseFixturesOnFixture)