11diff --git a/test/dynamo/cpython/3_13/test_baseexception.py b/test/dynamo/cpython/3_13/test_baseexception.py
2- index e599b02c17d..750d7a84fb4 100644
2+ index e599b02c17d..057b6ec01b9 100644
33--- a/test/dynamo/cpython/3_13/test_baseexception.py
44+++ b/test/dynamo/cpython/3_13/test_baseexception.py
55@@ -1,10 +1,64 @@
@@ -78,7 +78,27 @@ index e599b02c17d..750d7a84fb4 100644
7878 self.assertEqual(len(exc_set), 0, "%s not accounted for" % exc_set)
7979
8080 interface_tests = ("length", "args", "str", "repr")
81- @@ -142,7 +193,7 @@ class ExceptionClassTests(unittest.TestCase):
81+ @@ -122,12 +173,13 @@ class ExceptionClassTests(unittest.TestCase):
82+ # in PyObject_SetAttr.
83+ import gc
84+ d = {}
85+ - class HashThisKeyWillClearTheDict(str):
86+ - def __hash__(self) -> int:
87+ - d.clear()
88+ - return super().__hash__()
89+ - class Value(str):
90+ - pass
91+ + with torch._dynamo.error_on_graph_break(False):
92+ + class HashThisKeyWillClearTheDict(str):
93+ + def __hash__(self) -> int:
94+ + d.clear()
95+ + return super().__hash__()
96+ + class Value(str):
97+ + pass
98+ exc = Exception()
99+
100+ d[HashThisKeyWillClearTheDict()] = Value() # refcount of Value() is 1 now
101+ @@ -142,7 +194,7 @@ class ExceptionClassTests(unittest.TestCase):
82102 gc.collect()
83103
84104
@@ -87,7 +107,31 @@ index e599b02c17d..750d7a84fb4 100644
87107
88108 """Test usage of exceptions"""
89109
90- @@ -208,5 +259,5 @@ class UsageTests(unittest.TestCase):
110+ @@ -182,8 +234,9 @@ class UsageTests(unittest.TestCase):
111+ # BaseException; the ability was not possible until BaseException's
112+ # introduction so no need to support new-style objects that do not
113+ # inherit from it.
114+ - class NewStyleClass(object):
115+ - pass
116+ + with torch._dynamo.error_on_graph_break(False):
117+ + class NewStyleClass(object):
118+ + pass
119+ self.raise_fails(NewStyleClass)
120+ self.raise_fails(NewStyleClass())
121+
122+ @@ -194,8 +247,9 @@ class UsageTests(unittest.TestCase):
123+ def test_catch_non_BaseException(self):
124+ # Trying to catch an object that does not inherit from BaseException
125+ # is not allowed.
126+ - class NonBaseException(object):
127+ - pass
128+ + with torch._dynamo.error_on_graph_break(False):
129+ + class NonBaseException(object):
130+ + pass
131+ self.catch_fails(NonBaseException)
132+ self.catch_fails(NonBaseException())
133+
134+ @@ -208,5 +262,5 @@ class UsageTests(unittest.TestCase):
91135 self.catch_fails("spam")
92136
93137
0 commit comments