zackcquic commented on a change in pull request #7952:
URL: https://github.com/apache/tvm/pull/7952#discussion_r640196943



##########
File path: tests/python/relay/test_pass_instrument.py
##########
@@ -168,3 +169,329 @@ def run_after_pass(self, mod, info):
     # Out of pass context scope, should be reset
     assert passes_counter.run_before_count == 0
     assert passes_counter.run_after_count == 0
+
+
+def test_enter_pass_ctx_exception(capsys):
+    @pass_instrument
+    class PI:
+        def __init__(self, id):
+            self.id = id
+
+        def enter_pass_ctx(self):
+            print(self.id + " enter ctx")
+
+        def exit_pass_ctx(self):
+            print(self.id + " exit ctx")
+
+    @pass_instrument
+    class PIBroken(PI):
+        def __init__(self, id):
+            super().__init__(id)
+
+        def enter_pass_ctx(self):
+            print(self.id + " enter ctx")
+            raise RuntimeError("Just a dummy error")
+
+    pass_ctx = tvm.transform.PassContext(instruments=[PI("%1"), 
PIBroken("%2"), PI("%3")])
+    with pytest.raises(tvm.error.TVMError):
+        with pass_ctx:
+            pass
+
+    assert "%1 enter ctx\n" "%2 enter ctx\n" == capsys.readouterr().out

Review comment:
       Thanks for the detail explaining. I totally agree.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to