Skip to content

Commit 95f6071

Browse files
committed
Try to fix the test on WASI
1 parent b0ca5f4 commit 95f6071

1 file changed

Lines changed: 14 additions & 7 deletions

File tree

Lib/test/test_capi/test_run.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -290,13 +290,20 @@ def _check_run_interactive(self, run, encode_filename, use_loop):
290290

291291
def check_run_interactive(self, run, encode_filename, use_loop=False):
292292
# Redirect stderr to a temporary file to hide '>>> ' from the REPL
293-
stderr_copy = os.dup(STDERR_FD)
294-
with tempfile.TemporaryFile() as tmp:
295-
try:
296-
os.dup2(tmp.fileno(), STDERR_FD)
297-
self._check_run_interactive(run, encode_filename, use_loop)
298-
finally:
299-
os.dup2(stderr_copy, STDERR_FD)
293+
try:
294+
stderr_copy = os.dup(STDERR_FD)
295+
except OSError:
296+
# On WASI, dup(STDERR_FD) fails with "OSError: [Errno 58] Not
297+
# supported". In this case, run the test without redirecting
298+
# stderr to a temporary file.
299+
self._check_run_interactive(run, encode_filename, use_loop)
300+
else:
301+
with tempfile.TemporaryFile() as tmp:
302+
try:
303+
os.dup2(tmp.fileno(), STDERR_FD)
304+
self._check_run_interactive(run, encode_filename, use_loop)
305+
finally:
306+
os.dup2(stderr_copy, STDERR_FD)
300307

301308
def test_run_interactiveone(self):
302309
# Test PyRun_InteractiveOne()

0 commit comments

Comments
 (0)