Move pytest-specific code from testlib to pytest [applied]