File tree Expand file tree Collapse file tree 2 files changed +4
-12
lines changed Expand file tree Collapse file tree 2 files changed +4
-12
lines changed Original file line number Diff line number Diff line change @@ -772,22 +772,18 @@ def test_seek(self) -> None:
772
772
im .seek (1 )
773
773
774
774
@pytest .mark .parametrize ("buffer" , (True , False ))
775
- def test_save_stdout (self , buffer : bool ) -> None :
776
- old_stdout = sys .stdout
775
+ def test_save_stdout (self , buffer : bool , monkeypatch : pytest .MonkeyPatch ) -> None :
777
776
778
777
class MyStdOut :
779
778
buffer = BytesIO ()
780
779
781
780
mystdout : MyStdOut | BytesIO = MyStdOut () if buffer else BytesIO ()
782
781
783
- sys . stdout = mystdout
782
+ monkeypatch . setattr ( sys , " stdout" , mystdout )
784
783
785
784
with Image .open (TEST_PNG_FILE ) as im :
786
785
im .save (sys .stdout , "PNG" )
787
786
788
- # Reset stdout
789
- sys .stdout = old_stdout
790
-
791
787
if isinstance (mystdout , MyStdOut ):
792
788
mystdout = mystdout .buffer
793
789
with Image .open (mystdout ) as reloaded :
Original file line number Diff line number Diff line change @@ -367,22 +367,18 @@ def test_mimetypes(tmp_path: Path) -> None:
367
367
368
368
369
369
@pytest .mark .parametrize ("buffer" , (True , False ))
370
- def test_save_stdout (buffer : bool ) -> None :
371
- old_stdout = sys .stdout
370
+ def test_save_stdout (buffer : bool , monkeypatch : pytest .MonkeyPatch ) -> None :
372
371
373
372
class MyStdOut :
374
373
buffer = BytesIO ()
375
374
376
375
mystdout : MyStdOut | BytesIO = MyStdOut () if buffer else BytesIO ()
377
376
378
- sys . stdout = mystdout
377
+ monkeypatch . setattr ( sys , " stdout" , mystdout )
379
378
380
379
with Image .open (TEST_FILE ) as im :
381
380
im .save (sys .stdout , "PPM" )
382
381
383
- # Reset stdout
384
- sys .stdout = old_stdout
385
-
386
382
if isinstance (mystdout , MyStdOut ):
387
383
mystdout = mystdout .buffer
388
384
with Image .open (mystdout ) as reloaded :
You can’t perform that action at this time.
0 commit comments