镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions tests/conftest_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -709,9 +709,8 @@ def Helper__ExceptionToHumanText__Single(exc: BaseException) -> str:
err_msg = "Exception ({}).".format(type(exc).__name__)
assert type(err_msg) is str

exc_info_lines = traceback.format_exception(exc)
assert type(exc_info_lines) is list
err_msg2 = "".join(exc_info_lines).strip()
err_msg2 = __class__.Helper__GetTraceBack(exc)
assert type(err_msg2) is str

if err_msg2 != "":
err_msg += " " + err_msg2
Expand Down Expand Up @@ -793,10 +792,21 @@ def Helper__GetExcMsg(exc: BaseException) -> str:
assert isinstance(exc, BaseException)

if isinstance(exc, AssertionError):
exc_info_lines = traceback.format_exception(exc)
assert type(exc_info_lines) is list
return "".join(exc_info_lines).strip()
return __class__.Helper__GetTraceBack(exc)

return str(exc)

# --------------------------------------------------------------------
@staticmethod
def Helper__GetTraceBack(exc: BaseException) -> str:
assert isinstance(exc, BaseException)

exc_info_lines = traceback.format_exception(
type(exc),
exc,
exc.__traceback__,
)
assert type(exc_info_lines) is list
return "".join(exc_info_lines).strip()

# /////////////////////////////////////////////////////////////////////////////
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from ...conftest_helpers import TestServices

import pytest
import logging


class TestSet001__Helper__ExceptionToHumanText__Single:
def test_001(self):
with pytest.raises(expected_exception=AssertionError) as x:
v = 1
assert v == 2

assert isinstance(x.value, AssertionError)

msg = TestServices.Helper__ExceptionToHumanText__Single(x.value)

logging.info("msg: {}".format(msg))

assert "Exception (AssertionError)." in msg
assert "v == 2" in msg
assert "AssertionError: assert 1 == 2" in msg
return
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
from ...conftest_helpers import TestServices

import pytest
import logging


class TestSet002__Helper__ExceptionToHumanText__Chain:
def test_001(self):
with pytest.raises(expected_exception=AssertionError) as x:
v = 1
assert v == 2

assert isinstance(x.value, AssertionError)

msg = TestServices.Helper__ExceptionToHumanText__Chain(x.value)

logging.info("msg: {}".format(msg))

assert "---- 1. Exception (AssertionError):" in msg
assert "v == 2" in msg
assert "AssertionError: assert 1 == 2" in msg
return

def test_002(self):
with pytest.raises(expected_exception=AssertionError) as x:
v = 1
try:
raise RuntimeError("aaa")
except Exception:
assert v == 2

assert isinstance(x.value, AssertionError)

msg = TestServices.Helper__ExceptionToHumanText__Chain(x.value)

logging.info("msg: {}".format(msg))

assert "---- 1. Exception (RuntimeError):" in msg
assert "aaa" in msg
assert "---- 2. Exception (AssertionError):" in msg
assert "v == 2" in msg
assert "AssertionError: assert 1 == 2" in msg
return
Empty file added tests/own/__init__.py
Empty file.
Loading