Background
AlterOpLayout (also Legalize) tests register different packed functions in each test for unit testing. The registry can only update an attribute if the plevel supplied to it is larger than the currently registered function. This causes slightly awkward tests shown by
Problem
Pytest runs all the tests in one process, which means all the tests share the registry. This means that a registered function in one test can be unknowingly/mistakingly called for some other test (in some other file) as well. The reason that we don’t see any failure today is because today pytest runs serially, and by luck, the tests that need the original alter_op_layout function run before the tests that overwrite the registered function.
Also, this problem will block our move to pytest-parallel/xdist (if we decide to do that).
Proposed Solution
I tried to use pytest --forked
which runs each test in a separate process ensuring that the registry is not re-used across tests. Using this I was able to run all the tests in the file, even when the plevel was same.
Is this the right approach? I hit this problem while working on https://github.com/apache/incubator-tvm/pull/4351 @tqchen @zhiics @yzhliu @haichen