Skip to content

Commit f1b13e3

Browse files
pythongh-117982: Make the test for closed file more portable in the C API tests
The behavior of fileno() after fclose() is undefined, but it is the only practical way to check whether the file was closed. Only test this on the known platforms (Linux, Windows, macOS), where we already tested that it works.
1 parent 7d369d4 commit f1b13e3

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

Modules/_testcapi/run.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,10 @@ run_fileexflags(PyObject *mod, PyObject *pos_args)
7474

7575
result = PyRun_FileExFlags(fp, filename, start, globals, locals, closeit, pflags);
7676

77-
#if !defined(__wasi__)
78-
/* The behavior of fileno() after fclose() is undefined. */
77+
#if defined(__linux__) || defined(MS_WINDOWS) || defined(__APPLE__)
78+
/* The behavior of fileno() after fclose() is undefined, but it is
79+
* the only practical way to check whether the file was closed.
80+
* Only test this on the known platforms. */
7981
if (closeit && result && fileno(fp) >= 0) {
8082
PyErr_SetString(PyExc_AssertionError, "File was not closed after excution");
8183
Py_DECREF(result);

0 commit comments

Comments
 (0)