Skip to content

Commit

Permalink
Use errors instead of failures in JUnit reports
Browse files Browse the repository at this point in the history
  • Loading branch information
priitlatt committed Oct 15, 2024
1 parent a3cfd98 commit a81273f
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 16 deletions.
4 changes: 3 additions & 1 deletion src/codemagic/models/junit/definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@ def errors(self) -> Optional[int]:
return sum(suite.errors for suite in self.test_suites if suite.errors)

@property
def failures(self) -> int:
def failures(self) -> Optional[int]:
"""Total number of failed tests from all testsuites."""
if all(suite.failures is None for suite in self.test_suites):
return None
return sum(suite.failures for suite in self.test_suites if suite.failures)

@property
Expand Down
4 changes: 2 additions & 2 deletions src/codemagic/models/xctests/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,8 @@ def _get_test_suite(cls, xc_test_suite: XcTestSuite, xc_test_result_summary: XcT
name=cls._get_test_suite_name(xc_test_suite),
tests=len(xc_test_suite.test_cases),
disabled=sum(xc_test_case.is_disabled() for xc_test_case in xc_test_suite.test_cases),
errors=None, # Xcode doesn't differentiate errors from failures
failures=sum(xc_test_case.is_failed() for xc_test_case in xc_test_suite.test_cases),
errors=sum(xc_test_case.is_failed() for xc_test_case in xc_test_suite.test_cases),
failures=None, # Xcode doesn't differentiate errors from failures, consider everything as error
package=xc_test_suite.name,
skipped=sum(xc_test_case.is_skipped() for xc_test_case in xc_test_suite.test_cases),
time=sum(xc_test_case.get_duration() for xc_test_case in xc_test_suite.test_cases),
Expand Down
15 changes: 8 additions & 7 deletions src/codemagic/tools/xcode_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -512,13 +512,14 @@ def run_test(
test_suites = None
self.logger.error(Colors.RED(f"Parsing test results failed\n{e}\n{e.stderr}"))
else:
if test_suites.errors is not None:
failures_message = f"{test_suites.failures} failures and {test_suites.errors} errors"
else:
failures_message = f"{test_suites.failures} failures"

message = f"Executed {test_suites.tests} tests with {failures_message} in {test_suites.time:.2f} seconds.\n"
self.echo(Colors.BLUE(message))
message = f"Executed {test_suites.tests} tests"
if test_suites.errors is not None and test_suites.failures is not None:
message = f"{message} with {test_suites.failures} failures and {test_suites.errors} errors"
elif test_suites.errors is not None:
message = f"{message} with {test_suites.errors} errors"
elif test_suites.failures is not None:
message = f"{message} with {test_suites.errors} failures"
self.echo(Colors.BLUE(f"{message} in {test_suites.time:.2f} seconds.\n"))
TestSuitePrinter(self.echo).print_test_suites(test_suites)
self._save_test_suite(xcresult, test_suites, output_dir, output_extension)

Expand Down
12 changes: 6 additions & 6 deletions tests/models/xctests/converter/test_xcode_16_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,17 +240,17 @@ def test_converter(mock_datetime, expected_properties):

assert test_suites.name == "Test - banaan"
assert test_suites.disabled == 0
assert test_suites.errors is None
assert test_suites.failures == 3
assert test_suites.errors == 3
assert test_suites.failures is None
assert test_suites.skipped == 1
assert test_suites.tests == 8
assert test_suites.time == 5.46875
assert len(test_suites.test_suites) == 2

ts = test_suites.test_suites[0] # Unit tests testsuite assertions
assert ts.disabled == 0
assert ts.errors is None
assert ts.failures == 2
assert ts.errors == 2
assert ts.failures is None
assert ts.name == "banaanTests [iOS 18.0 iPhone SE (3rd generation)]"
assert ts.package == "banaanTests"
assert ts.skipped == 1
Expand Down Expand Up @@ -301,8 +301,8 @@ def test_converter(mock_datetime, expected_properties):

ts = test_suites.test_suites[1] # UI tests testsuite assertions
assert ts.disabled == 0
assert ts.errors is None
assert ts.failures == 1
assert ts.errors == 1
assert ts.failures is None
assert ts.name == "banaanUITests [iOS 18.0 iPhone SE (3rd generation)]"
assert ts.package == "banaanUITests"
assert ts.skipped == 0
Expand Down

0 comments on commit a81273f

Please sign in to comment.