@@ -231,18 +231,18 @@ def test_closed_file_descriptor(self):
231
231
self .assert_raises_os_error (errno .EBADF , self .os .fdopen , fileno2 , ** kwargs )
232
232
233
233
def test_fdopen_twice (self ):
234
+ # regression test for #997
234
235
file_path = self .make_path ("some_file1" )
235
236
self .create_file (file_path , contents = "contents here1" )
236
237
fake_file = self .open (file_path , "r" , encoding = "utf8" )
237
238
fd = fake_file .fileno ()
238
- self .open (fd , encoding = "utf8" )
239
- if not IS_PYPY :
240
- with self .assertRaises (OSError ) as cm :
241
- self .open (fd , encoding = "utf8" )
242
- self .assertEqual (errno .EBADF , cm .exception .errno )
243
- else :
244
- self .open (fd , encoding = "utf8" )
245
- self .os .close (fd )
239
+ # note: we need to assign the files to objects,
240
+ # otherwise the file will be closed immediately in the CPython implementation
241
+ # note that this case is not (and will probably not be) handled in pyfakefs
242
+ file1 = self .open (fd , encoding = "utf8" ) # noqa: F841
243
+ file2 = self .open (fd , encoding = "utf8" ) # noqa: F841
244
+
245
+ self .os .close (fd )
246
246
247
247
def test_open_fd_write_mode_for_ro_file (self ):
248
248
# Create a writable file handle to a read-only file, see #967
@@ -3159,22 +3159,6 @@ def test_listdir_impossible_without_read_permission(self):
3159
3159
with self .open (file_path , encoding = "utf8" ) as f :
3160
3160
assert f .read () == "hey"
3161
3161
3162
- def test_fdopen_twice (self ):
3163
- file_path1 = self .make_path ("some_file1" )
3164
- file_path2 = self .make_path ("SOME_file1" )
3165
- self .create_file (file_path1 , contents = "contents here1" )
3166
-
3167
- fake_file1 = self .open (file_path2 , "r" , encoding = "utf8" )
3168
- fileno1 = fake_file1 .fileno ()
3169
- self .os .fdopen (fileno1 , encoding = "utf8" )
3170
- if not IS_PYPY :
3171
- with self .assertRaises (OSError ) as cm :
3172
- self .open (fileno1 , encoding = "utf8" )
3173
- self .assertEqual (errno .EBADF , cm .exception .errno )
3174
- else :
3175
- self .open (fileno1 , encoding = "utf8" )
3176
- self .os .close (fileno1 )
3177
-
3178
3162
def test_stat (self ):
3179
3163
directory = self .make_path ("xyzzy" )
3180
3164
directory1 = self .make_path ("XYZZY" )
0 commit comments