This is an automated email from the ASF dual-hosted git repository.

echuraev pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tvm.git


The following commit(s) were added to refs/heads/main by this push:
     new 2c48d7bf21 [Test] Improve check for TVMError exception in test_cast 
(#15138)
2c48d7bf21 is described below

commit 2c48d7bf21cbea2792aebf58e8c9ac085b4cdd38
Author: Krzysztof Parzyszek <[email protected]>
AuthorDate: Thu Jun 22 06:32:31 2023 -0500

    [Test] Improve check for TVMError exception in test_cast (#15138)
    
    The original code has
    ```
    with pytest.raises(tvm.error.TVMError):
        s.astype("int")
        assert "Can't cast a handle to other types" in str(e)
    ```
    The `astype` is expected to throw a TVMError exception, but if it does,
    the following assertion never gets executed.
    
    Add try/except to the test to verify that the expected exception is
    thrown.
---
 tests/python/unittest/test_tir_nodes.py | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/tests/python/unittest/test_tir_nodes.py 
b/tests/python/unittest/test_tir_nodes.py
index 7826b5960b..49816778f1 100644
--- a/tests/python/unittest/test_tir_nodes.py
+++ b/tests/python/unittest/test_tir_nodes.py
@@ -118,9 +118,12 @@ def test_cast():
     assert z.lanes == 4
 
     s = tvm.tir.StringImm("s")
-    with pytest.raises(tvm.error.TVMError) as cm:
-        s.astype("int")
-        assert "Can't cast a handle to other types" in str(cm.execption)
+    with pytest.raises(tvm.error.TVMError):
+        try:
+            s.astype("int")
+        except Exception as e:
+            assert "Can't cast a handle to other types" in str(e)
+            raise
 
 
 def test_attr():

Reply via email to