Skip to content

Commit 53877f8

Browse files
authored
Refactor subprocess tests to properly close stdout and improve output assertions (#200)
1 parent 6da3b94 commit 53877f8

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

tests/test_subprocess.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,6 @@ def test_run(fp, fake):
349349
assert process.stderr is None
350350

351351

352-
@pytest.mark.filterwarnings("ignore:unclosed file:ResourceWarning")
353352
@pytest.mark.parametrize("fake", [False, True])
354353
def test_universal_newlines(fp, fake):
355354
fp.allow_unregistered(not fake)
@@ -362,11 +361,12 @@ def test_universal_newlines(fp, fake):
362361
(PYTHON, "example_script.py"), universal_newlines=True, stdout=subprocess.PIPE
363362
)
364363
process.wait()
364+
output = process.stdout.read()
365+
process.stdout.close()
365366

366-
assert process.stdout.read() == "Stdout line 1\nStdout line 2\n"
367+
assert output == "Stdout line 1\nStdout line 2\n"
367368

368369

369-
@pytest.mark.filterwarnings("ignore:unclosed file:ResourceWarning")
370370
@pytest.mark.parametrize("fake", [False, True])
371371
def test_text(fp, fake):
372372
fp.allow_unregistered(not fake)
@@ -386,8 +386,10 @@ def test_text(fp, fake):
386386
(PYTHON, "example_script.py"), stdout=subprocess.PIPE, text=True
387387
)
388388
process.wait()
389+
output = process.stdout.read()
390+
process.stdout.close()
389391

390-
assert process.stdout.read().splitlines() == ["Stdout line 1", "Stdout line 2"]
392+
assert output.splitlines() == ["Stdout line 1", "Stdout line 2"]
391393

392394

393395
def test_binary(fp):

0 commit comments

Comments
 (0)