Lunderberg commented on a change in pull request #8010:
URL: https://github.com/apache/tvm/pull/8010#discussion_r639983407
##########
File path: python/tvm/testing.py
##########
@@ -701,11 +717,79 @@ def _target_to_requirement(target):
return []
+def _pytest_target_params(targets, excluded_targets=None, xfail_targets=None):
+ # Include unrunnable targets here. They get skipped by the
+ # pytest.mark.skipif in _target_to_requirement(), showing up as
+ # skipped tests instead of being hidden entirely.
+ if targets is None:
+ if excluded_targets is None:
+ excluded_targets = set()
+
+ if xfail_targets is None:
+ xfail_targets = set()
+
+ target_marks = []
+ for t in _get_targets():
+ # Excluded targets aren't included in the params at all.
+ if t["target_kind"] not in excluded_targets:
+
+ # Known failing targets are included, but are marked
+ # as expected to fail.
+ extra_marks = []
+ if t["target_kind"] in xfail_targets:
+ extra_marks.append(
+ pytest.mark.xfail(
+ reason='Known failing test for target
"{}"'.format(t["target_kind"])
+ )
+ )
+ target_marks.append((t["target"], extra_marks))
+
+ else:
+ target_marks = [(target, []) for target in targets]
+
+ return [
+ pytest.param(target, marks=_target_to_requirement(target) +
extra_marks)
+ for target, extra_marks in target_marks
+ ]
+
+
+def _auto_parametrize_target(metafunc):
+ """Automatically applies parametrize_targets
+
+ Used if a test function uses the "target" fixture, but isn't
+ already marked with @tvm.testing.parametrize_targets. Intended
+ for use in the pytest_generate_tests() handler of a conftest.py
+ file.
+
+ """
+ if "target" in metafunc.fixturenames:
+ parametrized_args = [
+ arg.strip()
+ for mark in metafunc.definition.iter_markers("parametrize")
+ for arg in mark.args[0].split(",")
+ ]
+
+ if "target" not in parametrized_args:
+ # Check if the function is marked with either excluded or
+ # known failing targets.
+ excluded_targets = getattr(metafunc.function,
"tvm_excluded_targets", [])
+ xfail_targets = getattr(metafunc.function,
"tvm_known_failing_targets", [])
+ metafunc.parametrize(
+ "target",
+ _pytest_target_params(None, excluded_targets, xfail_targets),
+ scope="session",
+ )
+
+
def parametrize_targets(*args):
"""Parametrize a test over all enabled targets.
- Use this decorator when you want your test to be run over a variety of
- targets and devices (including cpu and gpu devices).
+ Use this decorator when you want your test to be run over a
+ variety of targets and devices (including cpu and gpu devices).
+
+ Alternatively, a test that accepts the "target" and "dev" will
Review comment:
Good point, edited documentation to reflect new intended usage, and to
recommend that `exclude_targets` or `known_failing_targets` should typically be
used instead.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]