diff --git a/ward/terminal.py b/ward/terminal.py index 57b7de94..84a7d5f4 100644 --- a/ward/terminal.py +++ b/ward/terminal.py @@ -551,7 +551,9 @@ def generate_chart( ) def output_test_failed_location(self, test_result: TestResult): - if isinstance(test_result.error, TestFailure): + if isinstance(test_result.error, TestFailure) or isinstance( + test_result.error, AssertionError + ): print( indent(colored("Location:", color="cyan", attrs=["bold"]), INDENT), f"{test_result.test.path.relative_to(Path.cwd())}:{test_result.error.error_line}", diff --git a/ward/testing.py b/ward/testing.py index d2ff1afe..6538ad75 100644 --- a/ward/testing.py +++ b/ward/testing.py @@ -1,6 +1,8 @@ import asyncio import functools import inspect +import sys +import traceback import uuid from collections import defaultdict from contextlib import ExitStack, closing, redirect_stderr, redirect_stdout @@ -281,6 +283,11 @@ def get_result(self, outcome, exception=None): if outcome in (TestOutcome.PASS, TestOutcome.SKIP): result = TestResult(self, outcome) else: + if isinstance(exception, AssertionError): + exception.error_line = traceback.extract_tb( + exception.__traceback__, limit=-1 + )[0].lineno + result = TestResult( self, outcome,