Skip to content

Commit d467d98

Browse files
authored
allow reporters to log pure html code on test_info() (#35)
1 parent 67ffb57 commit d467d98

14 files changed

Lines changed: 51 additions & 42 deletions

testipy/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import logging
22

33

4-
__version__ = "0.10.4"
4+
__version__ = "0.10.5"
55
__app__ = "TestiPy"
66
__app_full__ = "Python Test Tool"
77
__author__ = "Pedro Nunes"

testipy/models/package_manager.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class TestInfo(NamedTuple):
1717
level: str
1818
info: str
1919
attachment: Dict[str, Any]
20+
true_html: bool
2021

2122

2223
class CommonDetails:
@@ -131,7 +132,7 @@ def __init__(self, parent: SuiteDetails, test_method_attr: TestMethodAttr, test_
131132
self.test_state: str = ""
132133
self.test_reason_of_state: str = ""
133134

134-
self._info: List[TestInfo] = list()
135+
self._info: List[TestInfo] = []
135136
self._test_step: StateCounter = StateCounter()
136137

137138
def get_rm(self) -> ReportManager:
@@ -189,8 +190,8 @@ def get_prio(self) -> int:
189190
def get_features(self) -> str:
190191
return self.test_method_attr.features
191192

192-
def add_info(self, ts: int, current_time: str, level: str, info: str, attachment: Dict):
193-
self._info.append(TestInfo(ts, current_time, str(level).upper(), info, attachment))
193+
def add_info(self, ts: int, current_time: str, level: str, info: str, attachment: Dict, true_html: bool):
194+
self._info.append(TestInfo(ts, current_time, str(level).upper(), info, attachment, true_html))
194195

195196
def get_info(self) -> List[TestInfo]:
196197
return list(self._info)

testipy/reporter/report_base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,8 @@ def startTest(self, sd: SuiteDetails, test_method_attr: TestMethodAttr, test_nam
131131
def start_test(self, current_test: TestDetails):
132132
pass
133133

134-
def test_info(self, current_test, info, level, attachment=None):
135-
current_test.add_info(get_timestamp(), get_current_date_time_ns(), level, info, attachment)
134+
def test_info(self, current_test, info, level, attachment=None, true_html=False):
135+
current_test.add_info(get_timestamp(), get_current_date_time_ns(), level, info, attachment, true_html)
136136

137137
def test_step(self, current_test, state: str, reason_of_state: str = "", description: str = "", take_screenshot: bool = False, qty: int = 1, exc_value: BaseException = None):
138138
current_test.test_step(state, reason_of_state=reason_of_state, description=description, qty=qty, exc_value=exc_value)

testipy/reporter/report_interfaces.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def start_test(self, current_test: TestDetails):
5353
pass
5454

5555
@abstractmethod
56-
def test_info(self, current_test: TestDetails, info: str, level: str, attachment: Dict=None):
56+
def test_info(self, current_test: TestDetails, info: str, level: str, attachment: Dict=None, true_html: bool = False):
5757
pass
5858

5959
@abstractmethod

testipy/reporter/report_manager.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,11 +151,11 @@ def start_test(self, current_test: TestDetails):
151151
raise
152152

153153
@synchronized
154-
def test_info(self, current_test: TestDetails, info: str, level: str = "DEBUG", attachment: Dict = None) -> ReportManager:
155-
super().test_info(current_test, info, level, attachment)
154+
def test_info(self, current_test: TestDetails, info: str, level: str = "DEBUG", attachment: Dict = None, true_html: bool = False) -> ReportManager:
155+
super().test_info(current_test, info, level, attachment, true_html)
156156
for reporter_name, reporter in self._reporters_list.items():
157157
try:
158-
reporter.test_info(current_test, info, str(level).upper(), attachment)
158+
reporter.test_info(current_test, info, str(level).upper(), attachment, true_html)
159159
except Exception as e:
160160
_exec_logger.critical(f"Internal error rm.test_info on {reporter_name}: {e}")
161161
if self.is_debugcode():

testipy/reporter/reporters/reporter_echo.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,10 @@ def start_test(self, current_test: TestDetails):
8686
print("-" * _line_size)
8787
print(f"> Starting test: {current_test} <".center(_line_size, "-"))
8888

89-
def test_info(self, current_test: TestDetails, info: str, level: str, attachment: Dict=None):
89+
def test_info(self, current_test: TestDetails, info: str, level: str, attachment: Dict=None, true_html: bool = False):
9090
full_name = current_test.get_full_name(with_cycle_number=True)
91-
usecase = current_test.get_usecase()
92-
93-
print(f"{level} {full_name}: {prettify(info)}")
91+
if not true_html:
92+
print(f"{level} {full_name}: {prettify(info)}")
9493

9594
def test_step(self,
9695
current_test: TestDetails,

testipy/reporter/reporters/reporter_excel.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def end_suite(self, sd: SuiteDetails):
9595
def start_test(self, current_test: TestDetails):
9696
pass
9797

98-
def test_info(self, current_test: TestDetails, info, level, attachment=None):
98+
def test_info(self, current_test: TestDetails, info, level, attachment=None, true_html: bool = False):
9999
pass
100100

101101
def test_step(

testipy/reporter/reporters/reporter_html.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ def end_suite(self, sd: SuiteDetails):
108108
def start_test(self, current_test: TestDetails):
109109
pass
110110

111-
def test_info(self, current_test: TestDetails, info, level, attachment=None):
111+
def test_info(self, current_test: TestDetails, info, level, attachment=None, true_html: bool = False):
112112
pass
113113

114114
def test_step(
@@ -328,8 +328,10 @@ def _format_info(current_test: TestDetails, ending_state: str, end_reason: str):
328328
str_res += escaped_text(" Took: ") + f"{format_duration(current_test.get_duration())}"
329329

330330
# add test info log
331-
for ts, current_time, level, info, attachment in current_test.get_info():
332-
data = f"<p>{escaped_text(info)}</p>{get_image_from_attachment(attachment)}"
331+
for ts, current_time, level, info, attachment, true_html in current_test.get_info():
332+
if not true_html:
333+
info = escaped_text(info)
334+
data = f"<p>{info}</p>{get_image_from_attachment(attachment)}"
333335
str_res += f"<hr><strong>{current_time} {level}</strong><br>{data}"
334336

335337
# add test steps

testipy/reporter/reporters/reporter_junit.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import annotations
22
from typing import List, TYPE_CHECKING
3+
from xml.sax.saxutils import escape
34
import os
45

56
from testipy import get_exec_logger
@@ -63,7 +64,7 @@ def end_suite(self, sd: SuiteDetails):
6364
def start_test(self, current_test: TestDetails):
6465
pass
6566

66-
def test_info(self, current_test: TestDetails, info, level, attachment=None):
67+
def test_info(self, current_test: TestDetails, info, level, attachment=None, true_html: bool = False):
6768
pass
6869

6970
def test_step(
@@ -204,17 +205,17 @@ def _generate_failure_detail(self, xml_file, fail_counters: StateCounter, test_c
204205
category = file = method = code = "-"
205206
line = 0
206207

207-
xml_file.write(f"{failure_type}: {reason_of_state}\n")
208-
xml_file.write(f"Category: {category}\n")
209-
xml_file.write(f"File: {file}\n")
210-
xml_file.write(f"Line: {line}\n")
211-
xml_file.write(f"Method: {method}\n")
212-
xml_file.write(f"Code: {code}\n")
208+
xml_file.write(f"Category: {escape(category)}\n")
209+
xml_file.write(f" Message: {escape(reason_of_state)}\n")
210+
xml_file.write(f" File: {escape(file)}\n")
211+
xml_file.write(f" Line: {line}\n")
212+
xml_file.write(f" Method: {escape(method)}\n")
213+
xml_file.write(f" Code: {escape(code)}\n")
213214

214215
xml_file.write(" </failure>\n")
215216

216217

217218
def string_fixer(text):
218219
if not isinstance(text, str):
219220
text = str(text)
220-
return text.replace('"', "'").replace("\n", " | ")
221+
return escape(text.replace('"', "'").replace("\n", " | "))

testipy/reporter/reporters/reporter_log.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,10 @@ def start_test(self, current_test: TestDetails):
150150
test_full_name = current_test.get_full_name(with_cycle_number=True)
151151
self.__log(f"Starting Test {test_full_name}", "INFO")
152152

153-
def test_info(self, current_test: TestDetails, info, level, attachment=None):
154-
test_full_name = current_test.get_full_name(with_cycle_number=True)
155-
self.__log(f"{test_full_name}: {info}", level)
153+
def test_info(self, current_test: TestDetails, info, level, attachment=None, true_html: bool = False):
154+
if not true_html:
155+
test_full_name = current_test.get_full_name(with_cycle_number=True)
156+
self.__log(f"{test_full_name}: {info}", level)
156157

157158
def test_step(
158159
self,

0 commit comments

Comments
 (0)