From 2bf339b07c4479135d2b3b8d4ff02cbd799d9ebb Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Sun, 4 Dec 2022 10:22:00 -0500 Subject: [PATCH] tests: check TypeError on Windows Signed-off-by: Henry Schreiner --- tests/test_subprocess.py | 49 ++++++++++++++++++++++++---------------- 1 file changed, 29 insertions(+), 20 deletions(-) diff --git a/tests/test_subprocess.py b/tests/test_subprocess.py index 7f841e8..a92fc9d 100644 --- a/tests/test_subprocess.py +++ b/tests/test_subprocess.py @@ -1,3 +1,4 @@ +import contextlib import getpass import os import platform @@ -14,17 +15,13 @@ PYTHON = sys.executable -win_path_skip = pytest.mark.skipif( - sys.platform.startswith("win") and sys.version_info < (3, 8), - reason="Path in subprocess not supported before 3.8 on Windows", -) path_or_str = pytest.mark.parametrize( "rtype,ptype", [ pytest.param(str, str, id="str"), - pytest.param(Path, str, marks=win_path_skip, id="path,str"), - pytest.param(str, Path, marks=win_path_skip, id="str,path"), - pytest.param(Path, Path, marks=win_path_skip, id="path"), + pytest.param(Path, str, id="path,str"), + pytest.param(str, Path, id="str,path"), + pytest.param(Path, Path, id="path"), ], ) @@ -184,21 +181,33 @@ def test_basic_process(fp, fake, rtype, ptype): stderr=None, ) - process = subprocess.Popen( - [ptype(PYTHON), "example_script.py"], - cwd=os.path.dirname(__file__), - stdout=subprocess.PIPE, - stderr=subprocess.PIPE, - ) - out, err = process.communicate() + if sys.platform.startswith("win") and sys.version_info < (3, 8) and ptype is Path: + condition = pytest.raises(TypeError) - assert process.poll() == 0 - assert process.returncode == 0 - assert process.pid > 0 + else: + + @contextlib.contextmanager + def null_context(): + yield + + condition = null_context() + + with condition: + process = subprocess.Popen( + [ptype(PYTHON), "example_script.py"], + cwd=os.path.dirname(__file__), + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + ) + out, err = process.communicate() + + assert process.poll() == 0 + assert process.returncode == 0 + assert process.pid > 0 - # splitlines is required to ignore differences between LF and CRLF - assert out.splitlines() == [b"Stdout line 1", b"Stdout line 2"] - assert err == b"" + # splitlines is required to ignore differences between LF and CRLF + assert out.splitlines() == [b"Stdout line 1", b"Stdout line 2"] + assert err == b"" @pytest.mark.parametrize("fake", [False, True])