2020-04-22 00:33:10 +00:00
|
|
|
from functools import wraps
|
|
|
|
|
2020-01-05 19:34:25 +00:00
|
|
|
import pytest
|
|
|
|
import torch.multiprocessing as mp
|
|
|
|
|
|
|
|
|
|
|
|
def pytest_configure(config):
|
|
|
|
config.addinivalue_line("markers", "spawn: spawn test in a separate process using torch.multiprocessing.spawn")
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.tryfirst
|
|
|
|
def pytest_pyfunc_call(pyfuncitem):
|
|
|
|
if pyfuncitem.get_closest_marker("spawn"):
|
|
|
|
testfunction = pyfuncitem.obj
|
|
|
|
funcargs = pyfuncitem.funcargs
|
|
|
|
testargs = tuple([funcargs[arg] for arg in pyfuncitem._fixtureinfo.argnames])
|
|
|
|
|
2020-04-22 00:33:10 +00:00
|
|
|
mp.spawn(wraps, (testfunction, testargs))
|
2020-01-05 19:34:25 +00:00
|
|
|
return True
|