1- import importlib
21import pickle
32import threading
43from textwrap import dedent
98# Raise SkipTest if subinterpreters not supported.
109_channels = import_helper .import_module ('_interpchannels' )
1110from concurrent import interpreters
12- from test .support import channels
11+ from test .support import channels , force_not_colorized
1312from .utils import _run_output , TestBase
1413
1514
@@ -35,8 +34,14 @@ def test_highlevel_reloaded(self):
3534 importlib.reload(channels)
3635 """ ));
3736
37+ @force_not_colorized
3838 def test_channel_id_types (self ):
3939 # See https://github.com/python/cpython/issues/143376.
40+ code = """\
41+ import _interpchannels
42+ import re
43+ from concurrent import interpreters
44+
4045 class End:
4146 __slots__ = ()
4247 def __new__(cls, chan=None):
@@ -48,18 +53,19 @@ def _id(self):
4853 class Send(End): pass
4954 class Recv(End): pass
5055
51- _ = importlib .reload (_channels )
52- # ensure that the following tests do not have the registered bad types
53- self .addCleanup (importlib .reload , _channels )
54- _ ._register_end_types (Send , Recv )
55- chan = _ ._channel_id (_ .create (), _resolve = True )
56+ _interpchannels._register_end_types(Send, Recv)
57+ chan = _interpchannels._channel_id(_interpchannels.create(), _resolve=True)
5658 interp = interpreters.create()
57- # The TypeError exception arises from our internal check,
58- # but subinterpreters use a generic exception message instead
59- # while retaining the original exception type.
60- err = "does not support cross-interpreter data"
61- with self .assertRaisesRegex (TypeError , err ):
59+ try:
6260 interp.prepare_main(chan=Send(chan))
61+ finally:
62+ interp.close()
63+ """
64+
65+ out , err = self .assert_python_failure ("-c" , code )
66+ self .assertEqual (out , '' )
67+ errmsg = "TypeError: '_id' attribute must be an _interpchannels.ChannelID object, not object"
68+ self .assertIn (errmsg , err )
6369
6470
6571class TestChannels (TestBase ):
0 commit comments