Skip to content

Commit 181f1e0

Browse files
Lunderbergylc
authored andcommitted
[Unittests] Added a meta-test for tvm.testing.fixture behavior in case of a broken fixture. (apache#8343)
In these cases, the test function should be marked as failing the setup, and should not run. This is pytest's default behavior, and should work whether or not a fixture is cached. Co-authored-by: Eric Lunderberg <elunderberg@octoml.ai>
1 parent 9a55ee7 commit 181f1e0

File tree

1 file changed

+36
-1
lines changed

1 file changed

+36
-1
lines changed

tests/python/unittest/test_tvm_testing_features.py

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@
2525
# This file tests features in tvm.testing, such as verifying that
2626
# cached fixtures are run an appropriate number of times. As a
2727
# result, the order of the tests is important. Use of --last-failed
28-
# or --failed-first while debugging this file is not advised.
28+
# or --failed-first while debugging this file is not advised. If
29+
# these tests are distributed/parallelized using pytest-xdist or
30+
# similar, all tests in this file should run sequentially on the same
31+
# node. (See https://stackoverflow.com/a/59504228)
2932

3033

3134
class TestTargetAutoParametrization:
@@ -145,5 +148,37 @@ def test_cached_count(self):
145148
assert self.cached_calls == len(self.param1_vals)
146149

147150

151+
class TestBrokenFixture:
152+
# Tests that use a fixture that throws an exception fail, and are
153+
# marked as setup failures. The tests themselves are never run.
154+
# This behavior should be the same whether or not the fixture
155+
# results are cached.
156+
157+
num_uses_broken_uncached_fixture = 0
158+
num_uses_broken_cached_fixture = 0
159+
160+
@tvm.testing.fixture
161+
def broken_uncached_fixture(self):
162+
raise RuntimeError("Intentionally broken fixture")
163+
164+
@pytest.mark.xfail(True, reason="Broken fixtures should result in a failing setup", strict=True)
165+
def test_uses_broken_uncached_fixture(self, broken_uncached_fixture):
166+
type(self).num_uses_broken_fixture += 1
167+
168+
def test_num_uses_uncached(self):
169+
assert self.num_uses_broken_uncached_fixture == 0
170+
171+
@tvm.testing.fixture(cache_return_value=True)
172+
def broken_cached_fixture(self):
173+
raise RuntimeError("Intentionally broken fixture")
174+
175+
@pytest.mark.xfail(True, reason="Broken fixtures should result in a failing setup", strict=True)
176+
def test_uses_broken_cached_fixture(self, broken_cached_fixture):
177+
type(self).num_uses_broken_cached_fixture += 1
178+
179+
def test_num_uses_cached(self):
180+
assert self.num_uses_broken_cached_fixture == 0
181+
182+
148183
if __name__ == "__main__":
149184
sys.exit(pytest.main(sys.argv))

0 commit comments

Comments
 (0)