Skip to content

Commit aa85498

Browse files
committed
Fix resource and encodingwarnings caused by test code
1 parent 1ad041d commit aa85498

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

tests/test_xopen.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -642,15 +642,17 @@ def test_pass_bytesio_for_reading_and_writing(ext, threads):
642642
def test_xopen_stdin(monkeypatch, ext, threads):
643643
if ext == ".zst" and zstandard is None:
644644
return
645-
with open(TEST_DIR / f"file.txt{ext}", "rt") as in_file:
645+
# Add encoding to suppress encoding warnings
646+
with open(TEST_DIR / f"file.txt{ext}", "rt", encoding="latin-1") as in_file:
646647
monkeypatch.setattr("sys.stdin", in_file)
647648
with xopen("-", "rt", threads=threads) as f:
648649
data = f.read()
649650
assert data == CONTENT
650651

651652

652653
def test_xopen_stdout(monkeypatch):
653-
with tempfile.TemporaryFile(mode="w+t") as raw:
654+
# Add encoding to suppress encoding warnings
655+
with tempfile.TemporaryFile(mode="w+t", encoding="latin-1") as raw:
654656
monkeypatch.setattr("sys.stdout", raw)
655657
with xopen("-", "wt") as f:
656658
f.write("Hello world!")
@@ -668,6 +670,7 @@ def test_xopen_read_from_pipe(ext, threads):
668670
with xopen(process.stdout, "rt", threads=threads) as f:
669671
data = f.read()
670672
process.wait()
673+
process.stdout.close()
671674
assert data == CONTENT
672675

673676

@@ -685,4 +688,5 @@ def test_xopen_write_to_pipe(threads, ext):
685688
with xopen(process.stdout, "rt", threads=threads) as f:
686689
data = f.read()
687690
process.wait()
691+
process.stdout.close()
688692
assert data == CONTENT

0 commit comments

Comments
 (0)