@@ -44,14 +44,15 @@ def run_repl(
4444 * ,
4545 cmdline_args : list [str ] | None = None ,
4646 cwd : str | None = None ,
47+ skip : bool = False ,
4748 ) -> tuple [str , int ]:
4849 temp_dir = None
4950 if cwd is None :
5051 temp_dir = tempfile .TemporaryDirectory (ignore_cleanup_errors = True )
5152 cwd = temp_dir .name
5253 try :
5354 return self ._run_repl (
54- repl_input , env = env , cmdline_args = cmdline_args , cwd = cwd
55+ repl_input , env = env , cmdline_args = cmdline_args , cwd = cwd , skip = skip ,
5556 )
5657 finally :
5758 if temp_dir is not None :
@@ -64,6 +65,7 @@ def _run_repl(
6465 env : dict | None ,
6566 cmdline_args : list [str ] | None ,
6667 cwd : str ,
68+ skip : bool ,
6769 ) -> tuple [str , int ]:
6870 assert pty
6971 master_fd , slave_fd = pty .openpty ()
@@ -121,7 +123,10 @@ def _run_repl(
121123 except subprocess .TimeoutExpired :
122124 process .kill ()
123125 exit_code = process .wait ()
124- return "" .join (output ), exit_code
126+ output = "" .join (output )
127+ if skip and "can't use pyrepl" in output :
128+ self .skipTest ("pyrepl not available" )
129+ return output , exit_code
125130
126131
127132class TestCursorPosition (TestCase ):
@@ -1282,9 +1287,7 @@ def setUp(self):
12821287 def test_exposed_globals_in_repl (self ):
12831288 pre = "['__builtins__'"
12841289 post = "'__loader__', '__name__', '__package__', '__spec__']"
1285- output , exit_code = self .run_repl (["sorted(dir())" , "exit()" ])
1286- if "can't use pyrepl" in output :
1287- self .skipTest ("pyrepl not available" )
1290+ output , exit_code = self .run_repl (["sorted(dir())" , "exit()" ], skip = True )
12881291 self .assertEqual (exit_code , 0 )
12891292
12901293 # if `__main__` is not a file (impossible with pyrepl)
@@ -1336,20 +1339,19 @@ def _run_repl_globals_test(self, expectations, *, as_file=False, as_module=False
13361339 commands ,
13371340 cmdline_args = [str (mod )],
13381341 env = clean_env ,
1342+ skip = True ,
13391343 )
13401344 elif as_module :
13411345 output , exit_code = self .run_repl (
13421346 commands ,
13431347 cmdline_args = ["-m" , "blue.calx" ],
13441348 env = clean_env ,
13451349 cwd = td ,
1350+ skip = True ,
13461351 )
13471352 else :
13481353 self .fail ("Choose one of as_file or as_module" )
13491354
1350- if "can't use pyrepl" in output :
1351- self .skipTest ("pyrepl not available" )
1352-
13531355 self .assertEqual (exit_code , 0 )
13541356 for var , expected in expectations .items ():
13551357 with self .subTest (var = var , expected = expected ):
@@ -1387,9 +1389,7 @@ def test_python_basic_repl(self):
13871389 "exit()\n " )
13881390
13891391 env .pop ("PYTHON_BASIC_REPL" , None )
1390- output , exit_code = self .run_repl (commands , env = env )
1391- if "can\' t use pyrepl" in output :
1392- self .skipTest ("pyrepl not available" )
1392+ output , exit_code = self .run_repl (commands , env = env , skip = True )
13931393 self .assertEqual (exit_code , 0 )
13941394 self .assertIn ("True" , output )
13951395 self .assertNotIn ("False" , output )
@@ -1456,9 +1456,7 @@ def check(output, exitcode):
14561456 self .assertIn ("division by zero" , output )
14571457 self .assertEqual (exitcode , 0 )
14581458 env .pop ("PYTHON_BASIC_REPL" , None )
1459- output , exit_code = self .run_repl (commands , env = env )
1460- if "can\' t use pyrepl" in output :
1461- self .skipTest ("pyrepl not available" )
1459+ output , exit_code = self .run_repl (commands , env = env , skip = True )
14621460 check (output , exit_code )
14631461
14641462 env ["PYTHON_BASIC_REPL" ] = "1"
@@ -1496,9 +1494,7 @@ def test_not_wiping_history_file(self):
14961494 def test_correct_filename_in_syntaxerrors (self ):
14971495 env = os .environ .copy ()
14981496 commands = "a b c\n exit()\n "
1499- output , exit_code = self .run_repl (commands , env = env )
1500- if "can't use pyrepl" in output :
1501- self .skipTest ("pyrepl not available" )
1497+ output , exit_code = self .run_repl (commands , env = env , skip = True )
15021498 self .assertIn ("SyntaxError: invalid syntax" , output )
15031499 self .assertIn ("<python-input-0>" , output )
15041500 commands = " b\n exit()\n "
@@ -1525,9 +1521,7 @@ def test_proper_tracebacklimit(self):
15251521 env .pop ("PYTHON_BASIC_REPL" , None )
15261522 with self .subTest (set_tracebacklimit = set_tracebacklimit ,
15271523 basic_repl = basic_repl ):
1528- output , exit_code = self .run_repl (commands , env = env )
1529- if "can't use pyrepl" in output :
1530- self .skipTest ("pyrepl not available" )
1524+ output , exit_code = self .run_repl (commands , env = env , skip = True )
15311525 self .assertIn ("in x1" , output )
15321526 if set_tracebacklimit :
15331527 self .assertNotIn ("in x2" , output )
@@ -1568,9 +1562,7 @@ def test_readline_history_file(self):
15681562 def test_history_survive_crash (self ):
15691563 env = os .environ .copy ()
15701564 commands = "1\n exit()\n "
1571- output , exit_code = self .run_repl (commands , env = env )
1572- if "can't use pyrepl" in output :
1573- self .skipTest ("pyrepl not available" )
1565+ output , exit_code = self .run_repl (commands , env = env , skip = True )
15741566
15751567 with tempfile .NamedTemporaryFile () as hfile :
15761568 env ["PYTHON_HISTORY" ] = hfile .name
0 commit comments