|
25 | 25 | # This file tests features in tvm.testing, such as verifying that
|
26 | 26 | # cached fixtures are run an appropriate number of times. As a
|
27 | 27 | # 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) |
29 | 32 |
|
30 | 33 |
|
31 | 34 | class TestTargetAutoParametrization:
|
@@ -145,5 +148,37 @@ def test_cached_count(self):
|
145 | 148 | assert self.cached_calls == len(self.param1_vals)
|
146 | 149 |
|
147 | 150 |
|
| 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 | + |
148 | 183 | if __name__ == "__main__":
|
149 | 184 | sys.exit(pytest.main(sys.argv))
|
0 commit comments