diff --git a/pythonFiles/tests/unittestadapter/test_execution.py b/pythonFiles/tests/unittestadapter/test_execution.py index f7306e37662e..ccf13d983c60 100644 --- a/pythonFiles/tests/unittestadapter/test_execution.py +++ b/pythonFiles/tests/unittestadapter/test_execution.py @@ -202,6 +202,9 @@ def test_failed_tests(): assert "outcome" in id_result assert id_result["outcome"] == "failure" assert "message" and "traceback" in id_result + assert "2 not greater than 3" in str(id_result["message"]) or "1 == 1" in str( + id_result["traceback"] + ) assert True diff --git a/pythonFiles/unittestadapter/execution.py b/pythonFiles/unittestadapter/execution.py index 0684ada8e44b..5f46bda95328 100644 --- a/pythonFiles/unittestadapter/execution.py +++ b/pythonFiles/unittestadapter/execution.py @@ -104,13 +104,18 @@ def formatResult( subtest: Union[unittest.TestCase, None] = None, ): tb = None - if error and error[2] is not None: - # Format traceback + + message = "" + # error is a tuple of the form returned by sys.exc_info(): (type, value, traceback). + if error is not None: + try: + message = f"{error[0]} {error[1]}" + except Exception: + message = "Error occurred, unknown type or value" formatted = traceback.format_exception(*error) + tb = "".join(formatted) # Remove the 'Traceback (most recent call last)' formatted = formatted[1:] - tb = "".join(formatted) - if subtest: test_id = subtest.id() else: @@ -119,7 +124,7 @@ def formatResult( result = { "test": test.id(), "outcome": outcome, - "message": str(error), + "message": message, "traceback": tb, "subtest": subtest.id() if subtest else None, }