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

Using pytest for integration tests. #4125

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 2 additions & 11 deletions run-tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import argparse
import subprocess
import pytest
import unittest


def run_code_tests(executable=False, folder: str = "unit", interpreter="python"):
Expand All @@ -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()
Expand Down
10 changes: 7 additions & 3 deletions tests/integration/test_models/standard_model_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#
import pybamm
import tests
import uuid

import numpy as np
import os
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
Loading