Fix bug in self.assertExpectedInline (#55149)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/55149
I was wondering why no one used this function. It's because it
doesn't work! Also a small doc improvement for expected inline.
Signed-off-by: Edward Z. Yang <ezyang@fb.com>
Test Plan: Imported from OSS
Reviewed By: zhangguanheng66
Differential Revision: D27523880
Pulled By: ezyang
fbshipit-source-id: a1d80c088ebf1c58a2b9b13d28f7f23d08c42e60
diff --git a/torch/testing/_internal/expecttest.py b/torch/testing/_internal/expecttest.py
index 1fdd4a1..6e1f2f0 100644
--- a/torch/testing/_internal/expecttest.py
+++ b/torch/testing/_internal/expecttest.py
@@ -230,7 +230,7 @@
lineno = EDIT_HISTORY.adjust_lineno(fn, lineno)
new, delta = replace_string_literal(old, lineno, actual)
- assert old != new, "Failed to substitute string at {}:{}".format(fn, lineno)
+ assert old != new, f"Failed to substitute string at {fn}:{lineno}; did you use triple quotes?"
# Only write the backup file the first time we hit the
# file
@@ -258,7 +258,7 @@
try:
callable(*args, **kwargs)
except exc_type as e:
- self.assertExpectedInline(str(e), expect)
+ self.assertExpectedInline(str(e), expect, skip=1)
return
# Don't put this in the try block; the AssertionError will catch it
self.fail(msg="Did not raise when expected to")