Make test_cpp_extensions_aot handle lack of pytest more gracefully (#53740)

Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/53740

Signed-off-by: Edward Z. Yang <ezyang@fb.com>

Test Plan: Imported from OSS

Reviewed By: albanD

Differential Revision: D26956603

Pulled By: ezyang

fbshipit-source-id: 09ff60b29c4bd64044f4c9f0b7e17ffed33c30db
This commit is contained in:
Edward Yang 2021-03-22 07:20:37 -07:00 committed by Facebook GitHub Bot
parent 7b939d934e
commit 4ffafbac40

View File

@ -8,14 +8,23 @@ import torch
import torch.backends.cudnn
import torch.utils.cpp_extension
import pytest
try:
import pytest
HAS_PYTEST = True
except ImportError as e:
HAS_PYTEST = False
# TODO: Rewrite these tests so that they can be collected via pytest without
# using run_test.py
try:
cpp_extension = pytest.importorskip("torch_test_cpp_extension.cpp")
msnpu_extension = pytest.importorskip("torch_test_cpp_extension.msnpu")
rng_extension = pytest.importorskip("torch_test_cpp_extension.rng")
if HAS_PYTEST:
cpp_extension = pytest.importorskip("torch_test_cpp_extension.cpp")
msnpu_extension = pytest.importorskip("torch_test_cpp_extension.msnpu")
rng_extension = pytest.importorskip("torch_test_cpp_extension.rng")
else:
import torch_test_cpp_extension.cpp as cpp_extension
import torch_test_cpp_extension.msnpu as msnpu_extension
import torch_test_cpp_extension.rng as rng_extension
except ImportError as e:
raise RuntimeError(
"test_cpp_extensions_aot.py cannot be invoked directly. Run "