Skip to content

Commit 8ae4ad6

Browse files
committed
CI: improve pytest parameter readability
1 parent 65e700f commit 8ae4ad6

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

conftest.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,21 @@ def pytest_runtest_makereport(item, call):
287287
result.outcome = 'passed'
288288

289289

290+
def pytest_make_parametrize_id(config, val, argname):
291+
"""
292+
Prevents pytest to make obsucre parameter names (param0, param1, ...)
293+
and default to str(val) instead for better log readability.
294+
"""
295+
# First see if it has a name
296+
if hasattr(val, '__name__'):
297+
return val.__name__
298+
# Then try str(val)
299+
try:
300+
return str(val)
301+
except Exception:
302+
return None # Fall back to default behavior
303+
304+
290305
# A list of optimization options/pipelines to be used in testing
291306
# regarding spatial and/or temporal blocking.
292307
opts_tiling = ['advanced',

devito/finite_differences/derivative.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
from collections.abc import Iterable
33
from functools import cached_property
44
from itertools import chain
5-
import numbers
65

76
import sympy
87

@@ -159,14 +158,12 @@ def _validate_expr(expr):
159158
"""
160159
if type(expr) is sympy.Derivative:
161160
raise ValueError("Cannot nest sympy.Derivative with devito.Derivative")
162-
elif isinstance(expr, numbers.Number):
163-
return sympy.S.Zero
164161
if not isinstance(expr, Differentiable):
165162
try:
166163
expr = diffify(expr)
167164
except Exception as e:
168165
d = type(expr)
169-
raise ValueError(f"`expr` must be a `Differentiable` type object not {d}") from e
166+
raise ValueError(f"`expr` must be a `Differentiable` not {d}") from e
170167
return expr
171168

172169
@staticmethod

0 commit comments

Comments
 (0)