Skip to content

Commit

Permalink
Skip pfft tests if the class can not imported
Browse files Browse the repository at this point in the history
  • Loading branch information
paugier committed Feb 8, 2024
1 parent bb501a1 commit 34bc5d8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
3 changes: 2 additions & 1 deletion plugins/fluidfft-pfft/tests/test_pfft.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ class Tests(TestCase):
pass


complete_test_class_3d("fft3d.mpi_with_pfft", Tests)
# Importing pfft can fail because of CPU incompatibility
complete_test_class_3d("fft3d.mpi_with_pfft", Tests, skip_if_import_error=False)
18 changes: 14 additions & 4 deletions src/fluidfft/fft3d/testing.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,29 @@
import numpy as np

from fluidfft import import_fft_class
from .operators import OperatorsPseudoSpectral3D, vector_product
import pytest

from fluiddyn.util import mpi

from fluidfft import import_fft_class
from .operators import OperatorsPseudoSpectral3D, vector_product

rank = mpi.rank
nb_proc = mpi.nb_proc


def complete_test_class_3d(method, test_class, cls=None):
def complete_test_class_3d(
method, test_class, cls=None, skip_if_import_error=True
):
short_name = method.split(".")[1]
if cls is None:
cls = import_fft_class(method)
cls = import_fft_class(method, raise_import_error=skip_if_import_error)

tests = make_testop_functions(cls)
if cls is None:
tests = {
key: pytest.mark.skip(reason="Class not importable")(function)
for key, function in tests.items()
}
for key, test in tests.items():
setattr(test_class, f"test_operator3d_{short_name}_{key}", test)

Expand Down

0 comments on commit 34bc5d8

Please sign in to comment.