Skip to content

[conftest] Advanced processing of logging #230

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Prev Previous commit
Next Next commit
[summary] An error count of each test is printed
  • Loading branch information
dmitry-lipetsk committed Apr 1, 2025
commit 24b20c837426ea020be77dc8586f9624925310e0
92 changes: 72 additions & 20 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ class TEST_PROCESS_STATS:
cUnexpectedTests: int = 0
cAchtungTests: int = 0

FailedTests = list[str]()
XFailedTests = list[str]()
FailedTests = list[str, int]()
XFailedTests = list[str, int]()
NotXFailedTests = list[str]()
AchtungTests = list[str]()

Expand All @@ -132,19 +132,23 @@ def incrementPassedTestCount() -> None:
__class__.cPassedTests += 1

# --------------------------------------------------------------------
def incrementFailedTestCount(testID: str) -> None:
def incrementFailedTestCount(testID: str, errCount: int) -> None:
assert type(testID) == str # noqa: E721
assert type(errCount) == int # noqa: E721
assert errCount >= 0
assert type(__class__.FailedTests) == list # noqa: E721

__class__.FailedTests.append(testID) # raise?
__class__.FailedTests.append((testID, errCount)) # raise?
__class__.cFailedTests += 1

# --------------------------------------------------------------------
def incrementXFailedTestCount(testID: str) -> None:
def incrementXFailedTestCount(testID: str, errCount: int) -> None:
assert type(testID) == str # noqa: E721
assert type(errCount) == int # noqa: E721
assert errCount >= 0
assert type(__class__.XFailedTests) == list # noqa: E721

__class__.XFailedTests.append(testID) # raise?
__class__.XFailedTests.append((testID, errCount)) # raise?
__class__.cXFailedTests += 1

# --------------------------------------------------------------------
Expand Down Expand Up @@ -329,26 +333,25 @@ def helper__makereport__call(
if type(call.excinfo.value) == _pytest.outcomes.Skipped: # noqa: E721
assert not hasattr(rep, "wasxfail")

TEST_PROCESS_STATS.incrementSkippedTestCount()

exitStatus = "SKIPPED"
reasonText = str(call.excinfo.value)
reasonMsgTempl = "SKIP REASON: {0}"

elif type(call.excinfo.value) == _pytest.outcomes.XFailed: # noqa: E721
TEST_PROCESS_STATS.incrementXFailedTestCount(testID)
TEST_PROCESS_STATS.incrementSkippedTestCount()

elif type(call.excinfo.value) == _pytest.outcomes.XFailed: # noqa: E721
exitStatus = "XFAILED"
reasonText = str(call.excinfo.value)
reasonMsgTempl = "XFAIL REASON: {0}"

TEST_PROCESS_STATS.incrementXFailedTestCount(testID, item_error_msg_count)

else:
exitStatus = "XFAILED"
assert hasattr(rep, "wasxfail")
assert rep.wasxfail is not None
assert type(rep.wasxfail) == str # noqa: E721

TEST_PROCESS_STATS.incrementXFailedTestCount(testID)

reasonText = rep.wasxfail
reasonMsgTempl = "XFAIL REASON: {0}"

Expand All @@ -358,6 +361,8 @@ def helper__makereport__call(
logging.error(call.excinfo.value)
item_error_msg_count += 1

TEST_PROCESS_STATS.incrementXFailedTestCount(testID, item_error_msg_count)

assert type(reasonText) == str # noqa: E721

if reasonText != "":
Expand All @@ -369,15 +374,15 @@ def helper__makereport__call(
assert call.excinfo is not None
assert call.excinfo.value is not None

TEST_PROCESS_STATS.incrementFailedTestCount(testID)

if type(call.excinfo.value) == SIGNAL_EXCEPTION: # noqa: E721
assert item_error_msg_count > 0
pass
else:
logging.error(call.excinfo.value)
item_error_msg_count += 1

TEST_PROCESS_STATS.incrementFailedTestCount(testID, item_error_msg_count)

exitStatus = "FAILED"
elif rep.outcome == "passed":
assert call.excinfo is None
Expand Down Expand Up @@ -676,11 +681,42 @@ def helper__print_test_list(tests: list[str]) -> None:

nTest = 0

while nTest < len(tests):
testID = tests[nTest]
assert type(testID) == str # noqa: E721
for t in tests:
assert type(t) == str # noqa: E721
assert t != ""
nTest += 1
logging.info(templateLine.format(nTest, testID))
logging.info(templateLine.format(nTest, t))


# ------------------------------------------------------------------------
def helper__print_test_list2(tests: list[str, int]) -> None:
assert type(tests) == list # noqa: E721

assert helper__calc_W(9) == 1
assert helper__calc_W(10) == 2
assert helper__calc_W(11) == 2
assert helper__calc_W(99) == 2
assert helper__calc_W(100) == 3
assert helper__calc_W(101) == 3
assert helper__calc_W(999) == 3
assert helper__calc_W(1000) == 4
assert helper__calc_W(1001) == 4

W = helper__calc_W(len(tests))

templateLine = "{0:0" + str(W) + "d}. {1} ({2})"

nTest = 0

for t in tests:
assert type(t) == tuple # noqa: E721
assert len(t) == 2
assert type(t[0]) == str # noqa: E721
assert type(t[1]) == int # noqa: E721
assert t[0] != ""
assert t[1] >= 0
nTest += 1
logging.info(templateLine.format(nTest, t[0], t[1]))


# /////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -714,20 +750,36 @@ def LOCAL__print_test_list(header: str, test_count: int, test_list: list[str]):
helper__print_test_list(test_list)
logging.info("")

def LOCAL__print_test_list2(
header: str, test_count: int, test_list: list[str, int]
):
assert type(header) == str # noqa: E721
assert type(test_count) == int # noqa: E721
assert type(test_list) == list # noqa: E721
assert header != ""
assert test_count >= 0
assert len(test_list) == test_count

LOCAL__print_line1_with_header(header)
logging.info("")
if len(test_list) > 0:
helper__print_test_list2(test_list)
logging.info("")

# fmt: off
LOCAL__print_test_list(
"ACHTUNG TESTS",
TEST_PROCESS_STATS.cAchtungTests,
TEST_PROCESS_STATS.AchtungTests,
)

LOCAL__print_test_list(
LOCAL__print_test_list2(
"FAILED TESTS",
TEST_PROCESS_STATS.cFailedTests,
TEST_PROCESS_STATS.FailedTests
)

LOCAL__print_test_list(
LOCAL__print_test_list2(
"XFAILED TESTS",
TEST_PROCESS_STATS.cXFailedTests,
TEST_PROCESS_STATS.XFailedTests,
Expand Down