@@ -43,14 +43,15 @@ def run_repl(
4343 * ,
4444 cmdline_args : list [str ] | None = None ,
4545 cwd : str | None = None ,
46+ skip : bool = False ,
4647 ) -> tuple [str , int ]:
4748 temp_dir = None
4849 if cwd is None :
4950 temp_dir = tempfile .TemporaryDirectory (ignore_cleanup_errors = True )
5051 cwd = temp_dir .name
5152 try :
5253 return self ._run_repl (
53- repl_input , env = env , cmdline_args = cmdline_args , cwd = cwd
54+ repl_input , env = env , cmdline_args = cmdline_args , cwd = cwd , skip = skip ,
5455 )
5556 finally :
5657 if temp_dir is not None :
@@ -63,6 +64,7 @@ def _run_repl(
6364 env : dict | None ,
6465 cmdline_args : list [str ] | None ,
6566 cwd : str ,
67+ skip : bool ,
6668 ) -> tuple [str , int ]:
6769 assert pty
6870 master_fd , slave_fd = pty .openpty ()
@@ -119,7 +121,10 @@ def _run_repl(
119121 except subprocess .TimeoutExpired :
120122 process .kill ()
121123 exit_code = process .wait ()
122- return "" .join (output ), exit_code
124+ output = "" .join (output )
125+ if skip and "can't use pyrepl" in output :
126+ self .skipTest ("pyrepl not available" )
127+ return output , exit_code
123128
124129
125130class TestCursorPosition (TestCase ):
@@ -1082,9 +1087,7 @@ def setUp(self):
10821087 def test_exposed_globals_in_repl (self ):
10831088 pre = "['__annotations__', '__builtins__'"
10841089 post = "'__loader__', '__name__', '__package__', '__spec__']"
1085- output , exit_code = self .run_repl (["sorted(dir())" , "exit()" ])
1086- if "can't use pyrepl" in output :
1087- self .skipTest ("pyrepl not available" )
1090+ output , exit_code = self .run_repl (["sorted(dir())" , "exit()" ], skip = True )
10881091 self .assertEqual (exit_code , 0 )
10891092
10901093 # if `__main__` is not a file (impossible with pyrepl)
@@ -1136,20 +1139,19 @@ def _run_repl_globals_test(self, expectations, *, as_file=False, as_module=False
11361139 commands ,
11371140 cmdline_args = [str (mod )],
11381141 env = clean_env ,
1142+ skip = True ,
11391143 )
11401144 elif as_module :
11411145 output , exit_code = self .run_repl (
11421146 commands ,
11431147 cmdline_args = ["-m" , "blue.calx" ],
11441148 env = clean_env ,
11451149 cwd = td ,
1150+ skip = True ,
11461151 )
11471152 else :
11481153 self .fail ("Choose one of as_file or as_module" )
11491154
1150- if "can't use pyrepl" in output :
1151- self .skipTest ("pyrepl not available" )
1152-
11531155 self .assertEqual (exit_code , 0 )
11541156 for var , expected in expectations .items ():
11551157 with self .subTest (var = var , expected = expected ):
@@ -1187,9 +1189,7 @@ def test_python_basic_repl(self):
11871189 "exit()\n " )
11881190
11891191 env .pop ("PYTHON_BASIC_REPL" , None )
1190- output , exit_code = self .run_repl (commands , env = env )
1191- if "can\' t use pyrepl" in output :
1192- self .skipTest ("pyrepl not available" )
1192+ output , exit_code = self .run_repl (commands , env = env , skip = True )
11931193 self .assertEqual (exit_code , 0 )
11941194 self .assertIn ("True" , output )
11951195 self .assertNotIn ("False" , output )
@@ -1256,9 +1256,7 @@ def check(output, exitcode):
12561256 self .assertIn ("division by zero" , output )
12571257 self .assertEqual (exitcode , 0 )
12581258 env .pop ("PYTHON_BASIC_REPL" , None )
1259- output , exit_code = self .run_repl (commands , env = env )
1260- if "can\' t use pyrepl" in output :
1261- self .skipTest ("pyrepl not available" )
1259+ output , exit_code = self .run_repl (commands , env = env , skip = True )
12621260 check (output , exit_code )
12631261
12641262 env ["PYTHON_BASIC_REPL" ] = "1"
@@ -1296,9 +1294,7 @@ def test_not_wiping_history_file(self):
12961294 def test_correct_filename_in_syntaxerrors (self ):
12971295 env = os .environ .copy ()
12981296 commands = "a b c\n exit()\n "
1299- output , exit_code = self .run_repl (commands , env = env )
1300- if "can't use pyrepl" in output :
1301- self .skipTest ("pyrepl not available" )
1297+ output , exit_code = self .run_repl (commands , env = env , skip = True )
13021298 self .assertIn ("SyntaxError: invalid syntax" , output )
13031299 self .assertIn ("<python-input-0>" , output )
13041300 commands = " b\n exit()\n "
@@ -1325,9 +1321,7 @@ def test_proper_tracebacklimit(self):
13251321 env .pop ("PYTHON_BASIC_REPL" , None )
13261322 with self .subTest (set_tracebacklimit = set_tracebacklimit ,
13271323 basic_repl = basic_repl ):
1328- output , exit_code = self .run_repl (commands , env = env )
1329- if "can't use pyrepl" in output :
1330- self .skipTest ("pyrepl not available" )
1324+ output , exit_code = self .run_repl (commands , env = env , skip = True )
13311325 self .assertIn ("in x1" , output )
13321326 if set_tracebacklimit :
13331327 self .assertNotIn ("in x2" , output )
0 commit comments