diff --git a/run-tests.py b/run-tests.py index b956773380..82b097cb91 100755 --- a/run-tests.py +++ b/run-tests.py @@ -12,7 +12,6 @@ import argparse import subprocess import pytest -import unittest def run_code_tests(executable=False, folder: str = "unit", interpreter="python"): @@ -37,18 +36,10 @@ def run_code_tests(executable=False, folder: str = "unit", interpreter="python") # currently activated virtual environment interpreter = sys.executable if executable is False: - if tests == "tests/unit": - ret = pytest.main(["-v", tests]) - else: - suite = unittest.defaultTestLoader.discover(tests, pattern="test*.py") - result = unittest.TextTestRunner(verbosity=2).run(suite) - ret = int(not result.wasSuccessful()) + ret = pytest.main(["-v", tests]) else: print(f"Running {folder} tests with executable {interpreter}") - if tests == "tests/unit": - cmd = [interpreter, "-m", "pytest", "-v", tests] - else: - cmd = [interpreter, "-m", "unittest", "discover", "-v", tests] + cmd = [interpreter, "-m", "pytest", "-v", tests] p = subprocess.Popen(cmd) try: ret = p.wait() diff --git a/tests/integration/test_models/standard_model_tests.py b/tests/integration/test_models/standard_model_tests.py index ac06f95c9f..7f0e9e6137 100644 --- a/tests/integration/test_models/standard_model_tests.py +++ b/tests/integration/test_models/standard_model_tests.py @@ -3,6 +3,7 @@ # import pybamm import tests +import uuid import numpy as np import os @@ -140,11 +141,14 @@ def test_sensitivities(self, param_name, param_value, output_name="Voltage [V]") ) def test_serialisation(self, solver=None, t_eval=None): + # Generating unique file names to avoid race conditions when run in parallel. + unique_id = uuid.uuid4() + file_name = f"test_model_{unique_id}" self.model.save_model( - "test_model", variables=self.model.variables, mesh=self.disc.mesh + file_name, variables=self.model.variables, mesh=self.disc.mesh ) - new_model = pybamm.load_model("test_model.json") + new_model = pybamm.load_model(file_name + ".json") # create new solver for re-created model if solver is not None: @@ -175,7 +179,7 @@ def test_serialisation(self, solver=None, t_eval=None): new_solution.all_ys[x], self.solution.all_ys[x], decimal=accuracy ) - os.remove("test_model.json") + os.remove(file_name + ".json") def test_all( self, param=None, disc=None, solver=None, t_eval=None, skip_output_tests=False