Skip to content

Commit 0694b08

Browse files
authored
MAINT: mock slowest test. (#13885)
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.
2 parents 7dab272 + 8655912 commit 0694b08

File tree

1 file changed

+24
-7
lines changed

1 file changed

+24
-7
lines changed

IPython/core/tests/test_interactiveshell.py

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import sys
1818
import tempfile
1919
import unittest
20+
import pytest
2021
from unittest import mock
2122

2223
from os.path import join
@@ -635,10 +636,23 @@ def test_control_c(self, *mocks):
635636
)
636637
self.assertEqual(ip.user_ns["_exit_code"], -signal.SIGINT)
637638

638-
def test_magic_warnings(self):
639-
for magic_cmd in ("pip", "conda", "cd"):
640-
with self.assertWarnsRegex(Warning, "You executed the system command"):
641-
ip.system_raw(magic_cmd)
639+
640+
@pytest.mark.parametrize("magic_cmd", ["pip", "conda", "cd"])
641+
def test_magic_warnings(magic_cmd):
642+
if sys.platform == "win32":
643+
to_mock = "os.system"
644+
expected_arg, expected_kwargs = magic_cmd, dict()
645+
else:
646+
to_mock = "subprocess.call"
647+
expected_arg, expected_kwargs = magic_cmd, dict(
648+
shell=True, executable=os.environ.get("SHELL", None)
649+
)
650+
651+
with mock.patch(to_mock, return_value=0) as mock_sub:
652+
with pytest.warns(Warning, match=r"You executed the system command"):
653+
ip.system_raw(magic_cmd)
654+
mock_sub.assert_called_once_with(expected_arg, **expected_kwargs)
655+
642656

643657
# TODO: Exit codes are currently ignored on Windows.
644658
class TestSystemPipedExitCode(ExitCodeChecks):
@@ -1089,9 +1103,12 @@ def test_run_cell_asyncio_run():
10891103

10901104

10911105
def test_should_run_async():
1092-
assert not ip.should_run_async("a = 5")
1093-
assert ip.should_run_async("await x")
1094-
assert ip.should_run_async("import asyncio; await asyncio.sleep(1)")
1106+
assert not ip.should_run_async("a = 5", transformed_cell="a = 5")
1107+
assert ip.should_run_async("await x", transformed_cell="await x")
1108+
assert ip.should_run_async(
1109+
"import asyncio; await asyncio.sleep(1)",
1110+
transformed_cell="import asyncio; await asyncio.sleep(1)",
1111+
)
10951112

10961113

10971114
def test_set_custom_completer():

0 commit comments

Comments
 (0)