Skip to content
This repository has been archived by the owner on Oct 1, 2024. It is now read-only.

Commit

Permalink
Merge pull request #128 from jayeshathila/origin/include_location_for…
Browse files Browse the repository at this point in the history
…_assertions

Include location footer in logs for AssertionErrors
  • Loading branch information
darrenburns authored Mar 7, 2020
2 parents 1573955 + 6c4fa42 commit 2450038
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
4 changes: 3 additions & 1 deletion ward/terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}",
Expand Down
7 changes: 7 additions & 0 deletions ward/testing.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 2450038

Please sign in to comment.