Skip to content

Commit

Permalink
MAINT: mock slowest test.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Carreau committed Feb 8, 2023
1 parent 56e6925 commit 5d359cc
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions IPython/core/tests/test_interactiveshell.py
Expand Up @@ -17,6 +17,7 @@
import sys
import tempfile
import unittest
import pytest
from unittest import mock

from os.path import join
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 5d359cc

Please sign in to comment.