Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/report-offending-file' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
kohsuke committed Feb 5, 2021
2 parents ba6f2c0 + 99cc9af commit 2a31efd
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 20 deletions.
43 changes: 23 additions & 20 deletions launchable/commands/record/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,25 +126,28 @@ def payload():
first = True # used to control ',' in printing

for p in self.reports:
# To understand JUnit XML format, https://llg.cubic.org/docs/junit/ is helpful
# TODO: robustness: what's the best way to deal with broken XML file, if any?
xml = JUnitXml.fromfile(p, self.junitxml_parse_func)
if isinstance(xml, JUnitXml):
testsuites = [suite for suite in xml]
elif isinstance(xml, TestSuite):
testsuites = [xml]
else:
# TODO: what is a Pythonesque way to do this?
assert False

for suite in testsuites:
for case in suite:
if not first:
yield ','
first = False
count += 1

yield json.dumps(CaseEvent.from_case_and_suite(self.path_builder, case, suite, p))
try:
# To understand JUnit XML format, https://llg.cubic.org/docs/junit/ is helpful
# TODO: robustness: what's the best way to deal with broken XML file, if any?
xml = JUnitXml.fromfile(p, self.junitxml_parse_func)
if isinstance(xml, JUnitXml):
testsuites = [suite for suite in xml]
elif isinstance(xml, TestSuite):
testsuites = [xml]
else:
# TODO: what is a Pythonesque way to do this?
assert False

for suite in testsuites:
for case in suite:
if not first:
yield ','
first = False
count += 1

yield json.dumps(CaseEvent.from_case_and_suite(self.path_builder, case, suite, p))
except Exception as e:
raise Exception("Failed to process a report file: %s" % p) from e
yield ']}'

def printer(f):
Expand All @@ -171,7 +174,7 @@ def printer(f):
res.raise_for_status()
res = client.request("patch", "{}/close".format(session_id), headers=headers)
res.raise_for_status()
click.echo("Processed {} tests".format(count))
click.echo("Recorded {} tests".format(count))
if count==0:
click.echo(click.style("Looks like tests didn't run? If not, make sure the right files/directories are passed",'yellow'))
except Exception as e:
Expand Down
Empty file.
21 changes: 21 additions & 0 deletions tests/commands/record/test_tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from pathlib import Path
import responses, traceback

from tests.cli_test_case import CliTestCase


class TestsTest(CliTestCase):

@responses.activate
def test_filename_in_error_message(self):
broken_xml = str(Path(__file__).parent.joinpath('../../data/broken.xml').resolve())
self.cli('record', 'tests', '--build', self.build_name, 'file', broken_xml)
# mock doesn't evaluate generator so we need to do so here
g = responses.calls[1].request.body
try:
b''.join(g)
except Exception as e:
# making sure the offending file path name is being printed.
self.assertIn(broken_xml, traceback.format_exc())
else:
self.fail("Expected to see an error")
1 change: 1 addition & 0 deletions tests/data/broken.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
this is not an XML!

0 comments on commit 2a31efd

Please sign in to comment.