Skip to content

Commit adacbbf

Browse files
[mypyc] Provide instructions for resolving missing test module on Windows (#19579)
Python doesn't come with the test module by default on Windows if installed through pymanager. Since `test.support.EqualToForwardRef` is used as part of the mypyc run tests, we should provide a helpful error message when the test fails due to the missing `test` module. Co-authored-by: Stanislav Terliakov <[email protected]>
1 parent 04f38f5 commit adacbbf

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

mypyc/test-data/run-tuples.test

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,23 @@ import sys
131131
from typing import Optional
132132
from native import ClassIR, FuncIR, Record
133133

134+
HAVE_TEST = False
134135
if sys.version_info >= (3, 14):
135-
from test.support import EqualToForwardRef
136-
type_forward_ref = EqualToForwardRef
137-
else:
136+
try:
137+
from test.support import EqualToForwardRef
138+
type_forward_ref = EqualToForwardRef
139+
HAVE_TEST = True
140+
except ImportError as e:
141+
# catch the case of a pymanager installed Python
142+
# without the test module. It is excluded by default
143+
# on Windows.
144+
msg = 'Missing "test" module.'
145+
if sys.platform == "win32":
146+
msg += (' Please install a version of Python with the test module.'
147+
' If you are using pymanager, try running pymanager install --force PythonTest\\<version>')
148+
raise ImportError(msg) from e
149+
150+
if not HAVE_TEST:
138151
from typing import ForwardRef
139152
type_forward_ref = ForwardRef
140153

0 commit comments

Comments
 (0)