1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
|
diff --git a/src/_pytest/_code/code.py b/src/_pytest/_code/code.py
index b80d53ca5f..cfa226bb74 100644
--- a/src/_pytest/_code/code.py
+++ b/src/_pytest/_code/code.py
@@ -424,15 +424,14 @@ def recursionindex(self) -> Optional[int]:
# which generates code objects that have hash/value equality
# XXX needs a test
key = entry.frame.code.path, id(entry.frame.code.raw), entry.lineno
- # print "checking for recursion at", key
values = cache.setdefault(key, [])
+ # Since Python 3.13 f_locals is a proxy, freeze it.
+ loc = dict(entry.frame.f_locals)
if values:
- f = entry.frame
- loc = f.f_locals
for otherloc in values:
if otherloc == loc:
return i
- values.append(entry.frame.f_locals)
+ values.append(loc)
return None
diff --git a/src/_pytest/pytester.py b/src/_pytest/pytester.py
index 31c6de7819..f9ab007a4d 100644
--- a/src/_pytest/pytester.py
+++ b/src/_pytest/pytester.py
@@ -289,7 +289,8 @@ def assert_contains(self, entries: Sequence[Tuple[str, str]]) -> None:
__tracebackhide__ = True
i = 0
entries = list(entries)
- backlocals = sys._getframe(1).f_locals
+ # Since Python 3.13, f_locals is not a dict, but eval requires a dict.
+ backlocals = dict(sys._getframe(1).f_locals)
while entries:
name, check = entries.pop(0)
for ind, call in enumerate(self.calls[i:]):
@@ -760,6 +761,9 @@ def _makefile(
) -> Path:
items = list(files.items())
+ if ext is None:
+ raise TypeError("ext must not be None")
+
if ext and not ext.startswith("."):
raise ValueError(
f"pytester.makefile expects a file extension, try .{ext} instead of {ext}"
diff --git a/testing/code/test_excinfo.py b/testing/code/test_excinfo.py
index 86e30dc483..b547451298 100644
--- a/testing/code/test_excinfo.py
+++ b/testing/code/test_excinfo.py
@@ -1,6 +1,7 @@
# mypy: allow-untyped-defs
from __future__ import annotations
+import fnmatch
import importlib
import io
import operator
@@ -237,7 +238,7 @@ def f(n):
n += 1
f(n)
- excinfo = pytest.raises(RuntimeError, f, 8)
+ excinfo = pytest.raises(RecursionError, f, 8)
traceback = excinfo.traceback
recindex = traceback.recursionindex()
assert recindex == 3
@@ -373,7 +374,10 @@ def test_excinfo_no_sourcecode():
except ValueError:
excinfo = _pytest._code.ExceptionInfo.from_current()
s = str(excinfo.traceback[-1])
- assert s == " File '<string>':1 in <module>\n ???\n"
+ # TODO: Since Python 3.13b1 under pytest-xdist, the * is `import
+ # sys;exec(eval(sys.stdin.readline()))` (execnet bootstrap code)
+ # instead of `???` like before. Is this OK?
+ fnmatch.fnmatch(s, " File '<string>':1 in <module>\n *\n")
def test_excinfo_no_python_sourcecode(tmp_path: Path) -> None:
diff --git a/testing/code/test_source.py b/testing/code/test_source.py
index 2fa8520579..a00259976c 100644
--- a/testing/code/test_source.py
+++ b/testing/code/test_source.py
@@ -370,7 +370,11 @@ class B:
pass
B.__name__ = B.__qualname__ = "B2"
- assert getfslineno(B)[1] == -1
+ # Since Python 3.13 this started working.
+ if sys.version_info >= (3, 13):
+ assert getfslineno(B)[1] != -1
+ else:
+ assert getfslineno(B)[1] == -1
def test_code_of_object_instance_with_call() -> None:
diff --git a/testing/test_cacheprovider.py b/testing/test_cacheprovider.py
index d7815f77b9..8728ae84fd 100644
--- a/testing/test_cacheprovider.py
+++ b/testing/test_cacheprovider.py
@@ -194,7 +194,7 @@ def test_custom_cache_dir_with_env_var(
assert pytester.path.joinpath("custom_cache_dir").is_dir()
-@pytest.mark.parametrize("env", ((), ("TOX_ENV_DIR", "/tox_env_dir")))
+@pytest.mark.parametrize("env", ((), ("TOX_ENV_DIR", "mydir/tox-env")))
def test_cache_reportheader(
env: Sequence[str], pytester: Pytester, monkeypatch: MonkeyPatch
) -> None:
diff --git a/testing/test_doctest.py b/testing/test_doctest.py
index d731121795..9b33d641a1 100644
--- a/testing/test_doctest.py
+++ b/testing/test_doctest.py
@@ -224,11 +224,7 @@ def test_doctest_unexpected_exception(self, pytester: Pytester):
"Traceback (most recent call last):",
' File "*/doctest.py", line *, in __run',
" *",
- *(
- (" *^^^^*",)
- if (3, 11, 0, "beta", 4) > sys.version_info >= (3, 11)
- else ()
- ),
+ *((" *^^^^*", " *", " *") if sys.version_info >= (3, 13) else ()),
' File "<doctest test_doctest_unexpected_exception.txt[1]>", line 1, in <module>',
"ZeroDivisionError: division by zero",
"*/test_doctest_unexpected_exception.txt:2: UnexpectedException",
@@ -385,7 +381,7 @@ def some_property(self):
"*= FAILURES =*",
"*_ [[]doctest[]] test_doctest_linedata_on_property.Sample.some_property _*",
"004 ",
- "005 >>> Sample().some_property",
+ "005 *>>> Sample().some_property",
"Expected:",
" 'another thing'",
"Got:",
diff --git a/testing/test_main.py b/testing/test_main.py
index 345aa1e62c..6294f66b36 100644
--- a/testing/test_main.py
+++ b/testing/test_main.py
@@ -3,7 +3,6 @@
import os
from pathlib import Path
import re
-import sys
from typing import Optional
from _pytest.config import ExitCode
@@ -45,32 +44,18 @@ def pytest_internalerror(excrepr, excinfo):
assert result.ret == ExitCode.INTERNAL_ERROR
assert result.stdout.lines[0] == "INTERNALERROR> Traceback (most recent call last):"
- end_lines = (
- result.stdout.lines[-4:]
- if (3, 11, 0, "beta", 4) > sys.version_info >= (3, 11)
- else result.stdout.lines[-3:]
- )
+ end_lines = result.stdout.lines[-3:]
if exc == SystemExit:
assert end_lines == [
f'INTERNALERROR> File "{c1}", line 4, in pytest_sessionstart',
'INTERNALERROR> raise SystemExit("boom")',
- *(
- ("INTERNALERROR> ^^^^^^^^^^^^^^^^^^^^^^^^",)
- if (3, 11, 0, "beta", 4) > sys.version_info >= (3, 11)
- else ()
- ),
"INTERNALERROR> SystemExit: boom",
]
else:
assert end_lines == [
f'INTERNALERROR> File "{c1}", line 4, in pytest_sessionstart',
'INTERNALERROR> raise ValueError("boom")',
- *(
- ("INTERNALERROR> ^^^^^^^^^^^^^^^^^^^^^^^^",)
- if (3, 11, 0, "beta", 4) > sys.version_info >= (3, 11)
- else ()
- ),
"INTERNALERROR> ValueError: boom",
]
if returncode is False:
|