Skip to content

Commit

Permalink
fix unittest output to remove print of only object reference (microso…
Browse files Browse the repository at this point in the history
…ft#22180)

the traceback object was incorrectly printed as just the reference to
the object in the error message. Ended up just removing it since it is
correctly printed in the traceback object which is where it should
ultimately belong. closes:
microsoft#22181

---------

Co-authored-by: Raymond Zhao <[email protected]>
  • Loading branch information
eleanorjboyd and rzhao271 authored Oct 10, 2023
1 parent 92c2a2f commit 0665506
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
3 changes: 3 additions & 0 deletions pythonFiles/tests/unittestadapter/test_execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
15 changes: 10 additions & 5 deletions pythonFiles/unittestadapter/execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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,
}
Expand Down

0 comments on commit 0665506

Please sign in to comment.