You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
From the docs, it seems like the intended way to write skip decorators (that you'd import from e.g. conftest.py) is to use skipif (https://docs.pytest.org/en/6.2.x/skipping.html#id1). However, the condition shown in the example is simple and doesn't need to interact with any other parametrizations. Is it possible to get skipif to work when you also need to inspect arguments as part of the condition to skip?
In https://github.com/scipy/scipy/blob/4a6db1500dc62870865fe7827524abd332a88fd9/scipy/conftest.py#L147-L180, we have decorators which perform the skips we want correctly, however, (IIUC) because we use skip rather than skipif, when we use -rsx, the skips are reported as coming from conftest.py, e.g. SKIPPED [27] scipy/conftest.py:159: is_isomorphic only supports NumPy backend. Is there a way to write the decorators such that the skips are reported from the test in which they originate?
We can recover that information from --verbose instead, but it would be much easier if this worked with -rsx. Cheers!
# conftest.pyarray_api_compatible=pytest.mark.parametrize("xp", xp_available_backends.values())
defskip_if_array_api_gpu(func):
reason="do not run with Array API on and not on CPU"# method gets there as a function so we cannot use inspect.ismethodif'.'infunc.__qualname__:
@wraps(func)defwrapped(self, *args, **kwargs):
xp=kwargs["xp"]
ifSCIPY_ARRAY_APIandSCIPY_DEVICE!='cpu':
ifxp.__name__=='cupy':
pytest.skip(reason=reason)
elifxp.__name__=='torch':
if'cpu'notintorch.empty(0).device.type:
pytest.skip(reason=reason)
returnfunc(self, *args, **kwargs)
else:
@wraps(func)defwrapped(*args, **kwargs):
xp=kwargs["xp"]
ifSCIPY_ARRAY_APIandSCIPY_DEVICE!='cpu':
ifxp.__name__=='cupy':
pytest.skip(reason=reason)
elifxp.__name__=='torch':
if'cpu'notintorch.empty(0).device.type:
pytest.skip(reason=reason)
returnfunc(*args, **kwargs)
returnwrapped
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
From the docs, it seems like the intended way to write skip decorators (that you'd import from e.g.
conftest.py
) is to useskipif
(https://docs.pytest.org/en/6.2.x/skipping.html#id1). However, the condition shown in the example is simple and doesn't need to interact with any other parametrizations. Is it possible to getskipif
to work when you also need to inspect arguments as part of the condition to skip?In https://github.com/scipy/scipy/blob/4a6db1500dc62870865fe7827524abd332a88fd9/scipy/conftest.py#L147-L180, we have decorators which perform the skips we want correctly, however, (IIUC) because we use
skip
rather thanskipif
, when we use-rsx
, the skips are reported as coming fromconftest.py
, e.g.SKIPPED [27] scipy/conftest.py:159: is_isomorphic only supports NumPy backend
. Is there a way to write the decorators such that the skips are reported from the test in which they originate?We can recover that information from
--verbose
instead, but it would be much easier if this worked with-rsx
. Cheers!x-ref https://stackoverflow.com/questions/77687258/how-to-write-complex-pytest-skip-decorators
Beta Was this translation helpful? Give feedback.
All reactions