Skip to content

Commit

Permalink
Switch assertWarnsOnceRegex logic to check any instead of all. (pytor…
Browse files Browse the repository at this point in the history
…ch#56434)

Summary:
Pull Request resolved: pytorch#56434

If we hit multiple TORCH_WARN from different sources when running the
statement, it makes more sense to me that we want to check the regex is
met in any one of the warning messages instead of all messages.

Test Plan: Imported from OSS

Reviewed By: mruberry

Differential Revision: D27871946

Pulled By: ailzhang

fbshipit-source-id: 5940a8e43e4cc91aef213ef01e48d506fd9a1132
  • Loading branch information
Ailing Zhang authored and Kushashwa Shrimali committed May 18, 2021
1 parent ea84d4f commit 3982ee1
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions torch/testing/_internal/common_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1469,10 +1469,10 @@ def assertWarnsOnceRegex(self, category, regex=''):
torch.set_warn_always(prev)
if len(ws) == 0:
self.fail('no warning caught')
for w in ws:
self.assertTrue(type(w.message) is category)
self.assertTrue(re.match(pattern, str(w.message)),
f'{pattern}, {w.message}')
self.assertTrue(any([type(w.message) is category for w in ws]))
self.assertTrue(
any([re.match(pattern, str(w.message)) for w in ws]),
f'{pattern}, {[w.message for w in ws if type(w.message) is category]}')

def assertExpected(self, s, subname=None):
r"""
Expand Down

0 comments on commit 3982ee1

Please sign in to comment.