From a62f1561cfa1f3eb1e15f955fb9077eab3125c1f Mon Sep 17 00:00:00 2001 From: nyanpasu64 Date: Wed, 29 Aug 2018 00:57:08 -0700 Subject: [PATCH] Fix output pipeline tests (unique Popen mocks) --- tests/conftest.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 1dd6668..17f9f30 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -10,11 +10,15 @@ if TYPE_CHECKING: @pytest.fixture def Popen(mocker: 'pytest_mock.MockFixture'): + real_Popen = subprocess.Popen + + def popen_factory(*args, **kwargs): + popen = mocker.create_autospec(real_Popen) + popen.stdin = open(os.devnull, "wb") + popen.stdout = open(os.devnull, "rb") + popen.wait.return_value = 0 + return popen + Popen = mocker.patch.object(subprocess, 'Popen', autospec=True) - popen = Popen.return_value - - popen.stdin = open(os.devnull, "wb") - popen.stdout = open(os.devnull, "rb") - popen.wait.return_value = 0 - + Popen.side_effect = popen_factory yield Popen