| 24 | |
| 25 | |
| 26 | class FindFuncs(ast.NodeVisitor): |
| 27 | def __init__(self, filename): |
| 28 | super().__init__() |
| 29 | self.__filename = filename |
| 30 | |
| 31 | def visit_Call(self, node): |
| 32 | p = ParseCall() |
| 33 | p.visit(node.func) |
| 34 | ast.NodeVisitor.generic_visit(self, node) |
| 35 | |
| 36 | if p.ls[-1] == 'simplefilter' or p.ls[-1] == 'filterwarnings': |
| 37 | if node.args and getattr(node.args[0], "value", None) == "ignore": |
| 38 | if not self.__filename.name.startswith("test_"): |
| 39 | raise AssertionError( |
| 40 | "ignore filters should only be used in tests; " |
| 41 | f"found in {self.__filename} on line {node.lineno}") |
| 42 | |
| 43 | if p.ls[-1] == 'warn' and ( |
| 44 | len(p.ls) == 1 or p.ls[-2] == 'warnings'): |
| 45 | |
| 46 | if "testing/tests/test_warnings.py" == self.__filename: |
| 47 | # This file |
| 48 | return |
| 49 | |
| 50 | # See if stacklevel or skip_file_prefixes exists: |
| 51 | if len(node.args) == 3: |
| 52 | return |
| 53 | args = {kw.arg for kw in node.keywords} |
| 54 | if "stacklevel" in args: |
| 55 | return |
| 56 | if "skip_file_prefixes" in args: |
| 57 | return |
| 58 | raise AssertionError( |
| 59 | "warnings should have an appropriate stacklevel or skip_file_prefixes; " |
| 60 | f"found in {self.__filename} on line {node.lineno}") |
| 61 | |
| 62 | |
| 63 | @pytest.mark.slow |
no outgoing calls
searching dependent graphs…