Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix parallel optimisation and increase coverage #299

Merged
merged 8 commits into from
Apr 22, 2024
44 changes: 28 additions & 16 deletions tests/unit/test_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,33 @@
import pytest


@pytest.mark.unit
def test_multiprocessing_init_non_win32(monkeypatch):
"""Test multiprocessing init on non-Windows platforms"""
monkeypatch.setattr(sys, "platform", "linux")
with patch("multiprocessing.set_start_method") as mock_set_start_method:
del sys.modules["pybop"]
importlib.import_module("pybop")
mock_set_start_method.assert_called_once_with("fork")
class TestImport:
@pytest.mark.unit
def test_multiprocessing_init_non_win32(self, monkeypatch):
"""Test multiprocessing init on non-Windows platforms"""
monkeypatch.setattr(sys, "platform", "linux")
# Unload pybop and its sub-modules
self.unload_pybop()
with patch("multiprocessing.set_start_method") as mock_set_start_method:
importlib.import_module("pybop")
mock_set_start_method.assert_called_once_with("fork")

@pytest.mark.unit
def test_multiprocessing_init_win32(self, monkeypatch):
"""Test multiprocessing init on Windows"""
monkeypatch.setattr(sys, "platform", "win32")
self.unload_pybop()
with patch("multiprocessing.set_start_method") as mock_set_start_method:
importlib.import_module("pybop")
mock_set_start_method.assert_called_once_with("spawn")

@pytest.mark.unit
def test_multiprocessing_init_win32(monkeypatch):
"""Test multiprocessing init on Windows"""
monkeypatch.setattr(sys, "platform", "win32")
del sys.modules["pybop"]
with patch("multiprocessing.set_start_method") as mock_set_start_method:
importlib.import_module("pybop")
mock_set_start_method.assert_called_once_with("spawn")
def unload_pybop(self):
"""
Unload pybop and its sub-modules. Credit PyBaMM team:
https://github.com/pybamm-team/PyBaMM/blob/develop/tests/unit/test_util.py
BradyPlanden marked this conversation as resolved.
Show resolved Hide resolved
"""
# Unload pybop and its sub-modules
for module_name in list(sys.modules.keys()):
base_module_name = module_name.split(".")[0]
if base_module_name == "pybop":
sys.modules.pop(module_name)
Loading