Prevent users from seeing hardcoded print stmt when hypothesis is not installed (#142398)

Fixes: #142357

Pull Request resolved: https://github.com/pytorch/pytorch/pull/142398
Approved by: https://github.com/zou3519
This commit is contained in:
Guilherme Leobas
2024-12-16 23:21:27 +00:00
committed by PyTorch MergeBot
parent 969b07b96f
commit 487343346e
2 changed files with 3 additions and 9 deletions

View File

@ -91,14 +91,8 @@ def is_forbidden_context_manager(ctx):
except ImportError:
pass
try:
from torch.testing._internal.jit_utils import (
_AssertRaisesRegexWithHighlightContext,
)
f_ctxs.append(_AssertRaisesRegexWithHighlightContext)
except ImportError:
pass
if m := sys.modules.get("torch.testing._internal.jit_utils"):
f_ctxs.append(m._AssertRaisesRegexWithHighlightContext)
return ctx in f_ctxs

View File

@ -2570,7 +2570,7 @@ try:
"pytorch_ci" if IS_CI else os.getenv('PYTORCH_HYPOTHESIS_PROFILE', 'dev')
)
except ImportError:
print('Fail to import hypothesis in common_utils, tests are not derandomized')
warnings.warn('Fail to import hypothesis in common_utils, tests are not derandomized', ImportWarning)
# Used in check_if_enable to see if a test method should be disabled by an issue,
# sanitizes a test method name from appended suffixes by @dtypes parametrization.