Debian Codegraph @

tests/conftest.py

raw symbols ◀ ▶ SCIP
1 Debian patch touch this file
•1 # Workaround for pytest 9.0.x bug with Python 3.14
2 # Fixed in pytest 9.1+
3 import ast
4 import bisect
5 import _pytest._code.source as _source
6
7
8 def _patched_get_statement_startend2(lineno, node):
9 values = []
10
11 for x in ast.walk(node):
12 if isinstance(x, (ast.ClassDef, ast.FunctionDef, ast.AsyncFunctionDef)):
13 for d in x.decorator_list:
14 values.append(d.lineno - 1)
15 if hasattr(x, "lineno"):
16 values.append(x.lineno - 1)
17 for name in ("finalbody", "orelse"):
18 val = getattr(x, name, None)
19 if isinstance(val, list) and val and hasattr(val[0], "lineno"):
20 values.append(val[0].lineno - 1 - 1)
21
22 values.sort()
23 insert_index = bisect.bisect_right(values, lineno)
24 if insert_index == 0:
25 return lineno, None
26 start = values[insert_index - 1]
27 end = None if insert_index >= len(values) else values[insert_index]
28 return start, end
29
30
31 _source.get_statement_startend2 = _patched_get_statement_startend2