diff --git a/probert/tests/__init__.py b/probert/tests/__init__.py index e69de29..9c1555c 100644 --- a/probert/tests/__init__.py +++ b/probert/tests/__init__.py @@ -0,0 +1,11 @@ +import shutil # noqa: F401 +from unittest import IsolatedAsyncioTestCase +from unittest.mock import patch + + +class ProbertTestCase(IsolatedAsyncioTestCase): + def setUp(self): + which = patch("shutil.which") + self.m_which = which.start() + self.m_which.return_value = '/bin/false' + self.addCleanup(which.stop) diff --git a/probert/tests/test_filesystem.py b/probert/tests/test_filesystem.py index 56f4200..580322c 100644 --- a/probert/tests/test_filesystem.py +++ b/probert/tests/test_filesystem.py @@ -27,6 +27,7 @@ get_swap_sizing, get_device_filesystem, ) +from probert.tests import ProbertTestCase def read_file(filename): @@ -60,9 +61,9 @@ async def test_expected_output_vg(self): assert expected == await get_swap_sizing(device) -@patch('probert.filesystem.shutil.which', new=Mock(return_value='/bin/false')) -class TestFilesystem(IsolatedAsyncioTestCase): +class TestFilesystem(ProbertTestCase): def setUp(self): + super().setUp() self.device = Mock() self.device.device_node = random_string() @@ -198,10 +199,11 @@ async def test_get_device_filesystem_sizing_ext4_no_min(self): self.assertEqual(expected, actual) -@patch('probert.filesystem.shutil.which', new=Mock(return_value=None)) -class TestFilesystemToolNotFound(IsolatedAsyncioTestCase): +class TestFilesystemToolNotFound(ProbertTestCase): def setUp(self): + super().setUp() self.device = Mock() + self.m_which.return_value = None async def test_ntfsresize_not_found(self): self.assertEqual(None, await get_ntfs_sizing(self.device)) diff --git a/probert/tests/test_os.py b/probert/tests/test_os.py index b08e45c..823d6e6 100644 --- a/probert/tests/test_os.py +++ b/probert/tests/test_os.py @@ -14,14 +14,13 @@ # along with this program. If not, see . import subprocess -from unittest import IsolatedAsyncioTestCase -from unittest.mock import Mock, patch +from unittest.mock import patch from probert.os import probe, _parse_osprober, _run_os_prober +from probert.tests import ProbertTestCase -@patch('probert.filesystem.shutil.which', new=Mock(return_value='/bin/false')) -class TestOsProber(IsolatedAsyncioTestCase): +class TestOsProber(ProbertTestCase): def tearDown(self): _run_os_prober.cache_clear() @@ -157,7 +156,10 @@ async def test_run_once(self, run): run.assert_called_once() -@patch('probert.filesystem.shutil.which', new=Mock(return_value=None)) -class TestOsProberNotFound(IsolatedAsyncioTestCase): +class TestOsProberNotFound(ProbertTestCase): + def setUp(self): + super().setUp() + self.m_which.return_value = None + async def test_os_prober_not_found(self): self.assertEqual(None, _run_os_prober())