From 3bab2b291d969972fbf7a403f1a285befc7c1cbb Mon Sep 17 00:00:00 2001 From: moto <855818+mthrok@users.noreply.github.com> Date: Fri, 31 Jul 2020 17:12:21 -0400 Subject: [PATCH] [CI] Make *nix unit test fail if C++ extension is not available (#847) Currently our test suites automatically/silently skip tests on C++ extension if it is not available. This is nice in local env, but in CI these tests should be enforced and reported as failure if C++ extension is not available. This PR adds switch for making tests fail if C++ extension is not available, and make CI for *nix fail if that's the case. --- .circleci/unittest/linux/scripts/run_test.sh | 1 + test/common_utils/case_utils.py | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/.circleci/unittest/linux/scripts/run_test.sh b/.circleci/unittest/linux/scripts/run_test.sh index 2945b56194..63bd5aa52d 100755 --- a/.circleci/unittest/linux/scripts/run_test.sh +++ b/.circleci/unittest/linux/scripts/run_test.sh @@ -12,6 +12,7 @@ eval "$(./conda/bin/conda shell.bash hook)" conda activate ./env python -m torch.utils.collect_env +export TORCHAUDIO_TEST_FAIL_IF_NO_EXTENSION=1 export PATH="${PWD}/third_party/install/bin/:${PATH}" if [ "${os}" == MacOSX ] ; then diff --git a/test/common_utils/case_utils.py b/test/common_utils/case_utils.py index 9c89ef6891..ad68eb4f52 100644 --- a/test/common_utils/case_utils.py +++ b/test/common_utils/case_utils.py @@ -67,4 +67,12 @@ def skipIfNoModule(module, display_name=None): skipIfNoSoxBackend = unittest.skipIf( 'sox' not in torchaudio.list_audio_backends(), 'Sox backend not available') skipIfNoCuda = unittest.skipIf(not torch.cuda.is_available(), reason='CUDA not available') -skipIfNoExtension = skipIfNoModule('torchaudio._torchaudio', 'torchaudio C++ extension') + + +def skipIfNoExtension(test_item): + if ( + not is_module_available('torchaudio._torchaudio') + and 'TORCHAUDIO_TEST_FAIL_IF_NO_EXTENSION' in os.environ + ): + raise RuntimeError('torchaudio C++ extension is not available.') + return unittest.skip('torchaudio C++ extension is not available')(test_item)