From 5d359cc5da54866d8e4c026d527679cb6d5747b3 Mon Sep 17 00:00:00 2001 From: Matthias Bussonnier Date: Tue, 3 Jan 2023 14:55:37 +0100 Subject: [PATCH] MAINT: mock slowest test. The slowest test of our CI is ~3sec as it use subprocess os/system. Mocking make it instantaneous. With our big elements matrix in CI that should save us a bunch of time in total from PR submission to green. --- IPython/core/tests/test_interactiveshell.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/IPython/core/tests/test_interactiveshell.py b/IPython/core/tests/test_interactiveshell.py index 982bd5a3b22..0a246013025 100644 --- a/IPython/core/tests/test_interactiveshell.py +++ b/IPython/core/tests/test_interactiveshell.py @@ -17,6 +17,7 @@ import sys import tempfile import unittest +import pytest from unittest import mock from os.path import join @@ -635,10 +636,20 @@ def test_control_c(self, *mocks): ) self.assertEqual(ip.user_ns["_exit_code"], -signal.SIGINT) - def test_magic_warnings(self): - for magic_cmd in ("pip", "conda", "cd"): - with self.assertWarnsRegex(Warning, "You executed the system command"): - ip.system_raw(magic_cmd) + +@pytest.mark.parametrize("magic_cmd", ["pip", "conda", "cd"]) +def test_magic_warnings(magic_cmd): + if sys.platform == "win32": + to_mock = "os.system" + else: + to_mock = "subprocess.call" + with mock.patch(to_mock, return_value=0) as mock_sub: + with pytest.warns(Warning, match=r"You executed the system command"): + ip.system_raw(magic_cmd) + mock_sub.assert_called_once_with( + magic_cmd, shell=True, executable=os.environ.get("SHELL", None) + ) + # TODO: Exit codes are currently ignored on Windows. class TestSystemPipedExitCode(ExitCodeChecks):