Skip to content

Commit 46a0483

Browse files
committed
[UnitTest] Use pytest's scope='session' for tvm.testing.parameter
Prior to this commit, the `tvm.testing.parameter` utility defined a fixture with the default `scope="function"`. However, this prevents use of these parameters as arguments for other fixtures that are themselves cached using pytest. Since these are parameters, not large values that would be expensive to compute, there is no downside to caching them at the pytest level. This commit updates the scope of fixtures generated using `tvm.testing.parameter` to use `scope="session"` instead of the default `scope="function"`.
1 parent c0a47ed commit 46a0483

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

python/tvm/testing/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1447,7 +1447,7 @@ def parameter(*values, ids=None, by_dict=None):
14471447

14481448
# Optional cls parameter in case a parameter is defined inside a
14491449
# class scope.
1450-
@pytest.fixture(params=values, ids=ids)
1450+
@pytest.fixture(params=values, ids=ids, scope="session")
14511451
def as_fixture(*_cls, request):
14521452
return request.param
14531453

tests/python/testing/test_tvm_testing_features.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,5 +290,16 @@ def test_uses_deepcopy(self, fixture_with_deepcopy):
290290
pass
291291

292292

293+
class TestPytestCache:
294+
param = tvm.testing.parameter(1, 2, 3)
295+
296+
@pytest.fixture(scope="class")
297+
def cached_fixture(self, param):
298+
return param * param
299+
300+
def test_uses_cached_fixture(self, param, cached_fixture):
301+
assert cached_fixture == param * param
302+
303+
293304
if __name__ == "__main__":
294305
tvm.testing.main()

0 commit comments

Comments
 (0)