Skip to content

Commit

Permalink
Merge pull request #2 from zytedata/ZIDE-1368-circle-ci-merge-multipl…
Browse files Browse the repository at this point in the history
…e-report-html-files

Zide 1368 circle ci merge multiple report html files
  • Loading branch information
santAndras authored Apr 2, 2024
2 parents 261fc80 + 5f948e9 commit f12b943
Show file tree
Hide file tree
Showing 10 changed files with 1,937 additions and 17 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -161,3 +161,4 @@ cython_debug/
junit.xml
.vscode/launch.json
.vscode/settings.json
report.html
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,21 @@ Merge multiples files into one!

Current supported files to merge:

- junit.xml
- junit.xml (Ref.: [JUnitXML file](https://docs.pytest.org/en/7.1.x/how-to/output.html#creating-junitxml-format-files))
- report.html (Ref.: [self-contained HTML report file](https://pytest-html.readthedocs.io/en/latest/user_guide.html#enhancing-reports))

Example:
Example for junit.xml file merge:

```
from onefile.junit import merge_junit_files
merge_junit_files(["junit_1.xml", "junit_2.xml", "junit_3.xml"])
```

Example for report.html file merge:

```
from onefile.report_html import merge_report_html_files
merge_junit_files(["report_html_1.xml", "report_html_2.xml", "report_html_3.xml"])
```
39 changes: 26 additions & 13 deletions onefile/junit.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ def __init__(self, message: str, text: Optional[str] = None):

def __repr__(self):
return (
f"{self.__class__.__name__}(message='{self.message}', text='{self.text}')"
f"{self.__class__.__name__}(message='{self.message}', "
f"text='{self.text}')"
)


Expand All @@ -35,7 +36,8 @@ def __init__(self, skip_type: str, message: str, text: str):

def __repr__(self):
return (
f"Skipped(message='{self.message}', type='{self.type}', text='{self.text})"
f"Skipped(message='{self.message}', type='{self.type}', "
f"text='{self.text})"
)


Expand Down Expand Up @@ -64,8 +66,8 @@ def __repr__(self):
return (
f"TestCase(classname='{self.classname}', name='{self.name}', "
f"file='{self.file}', line='{self.line}', "
f"time='{self.time}', error='{self.error}', failure='{self.failure}', "
f"skipped='{self.skipped}')"
f"time='{self.time}', error='{self.error}', "
f"failure='{self.failure}', skipped='{self.skipped}')"
)


Expand Down Expand Up @@ -98,7 +100,8 @@ def __repr__(self):
return (
f"TestSuite(name='{self.name}', errors={self.errors}, "
f"failures={self.failures}, skipped={self.skipped}, "
f"tests={self.tests}, time={self.time}, timestamp='{self.timestamp}', "
f"tests={self.tests}, time={self.time}, "
f"timestamp='{self.timestamp}', "
f"hostname='{self.hostname}', testcases={self.test_cases})"
)

Expand Down Expand Up @@ -142,15 +145,21 @@ def parse_junit_xml(file_paths: list[str]) -> TestSuites:

if (error_elem := test_case_elem.find("error")) is not None:
error = Error(
message=error_elem.get("message", ""), text=error_elem.text
message=error_elem.get("message", ""),
text=error_elem.text,
)

if (failure_elem := test_case_elem.find("failure")) is not None:
if (
failure_elem := test_case_elem.find("failure")
) is not None:
failure = Failure(
message=failure_elem.get("message", ""), text=failure_elem.text
message=failure_elem.get("message", ""),
text=failure_elem.text,
)

if (skipped_elem := test_case_elem.find("skipped")) is not None:
if (
skipped_elem := test_case_elem.find("skipped")
) is not None:
skipped = Skipped(
skip_type=skipped_elem.get("type", ""),
message=skipped_elem.get("message", ""),
Expand Down Expand Up @@ -207,11 +216,15 @@ def merge_test_suites(test_suites: TestSuites) -> TestSuite:
)

if existing_tc_index is not None:
logging.debug(f"Test case found!")
logging.debug("Test case found!")
if is_test_suite_timestamp_updated:
logging.debug("Test suite timestamp is updated!")
logging.debug("Update final test suite errors, failures, skipped")
existing_tc = final_test_suite.test_cases[existing_tc_index]
logging.debug(
"Update final test suite errors, failures, skipped"
)
existing_tc = final_test_suite.test_cases[
existing_tc_index
]

if loaded_testcase.error and not existing_tc.error:
logging.debug("Increase errors attribute!")
Expand Down Expand Up @@ -241,7 +254,7 @@ def merge_test_suites(test_suites: TestSuites) -> TestSuite:
else:
logging.debug("Test suite timestamp is NOT updated!")
else:
logging.debug(f"Test case NOT found!")
logging.debug("Test case NOT found!")
if loaded_testcase.error:
final_test_suite.errors += 1
if loaded_testcase.failure:
Expand Down
Loading

0 comments on commit f12b943

Please sign in to comment.