Skip to content

Commit

Permalink
fix(pylint,pytest): detect failures and error message associated with…
Browse files Browse the repository at this point in the history
… the task (kubeflow#818)

* fix(pylint): detect failures and erros associated with the task

* do not break if neither failure or failure element doesn't have message attribute

* send xml files to artifacts folder to get detected by spyglass

* parse all the tests to xml

* path for pytest gets added from generate_xml function

* Revert "path for pytest gets added from generate_xml function"

This reverts commit 8be433afb7f93fa9017dad1a7870d9929c4d4e7b.

* add only: path for pytest gets added from generate_xml function
  • Loading branch information
subodh101 authored Nov 25, 2020
1 parent 6012114 commit f2bbbcd
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ spec:
- name: py-lint
params:
- name: artifacts-gcs
value: $(params.artifacts-gcs)
value: $(params.artifacts-gcs)/artifacts/junit_py-lint
- name: lint-src-dir
value: $(params.lint-src-dir)
resources:
Expand All @@ -35,7 +35,7 @@ spec:
- name: py-test
params:
- name: artifacts-gcs
value: $(params.artifacts-gcs)
value: $(params.artifacts-gcs)/artifacts
- name: test-src-dir
value: $(params.test-src-dir)
resources:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ spec:
- name: py-lint
params:
- name: artifacts-gcs
value: $(params.artifacts-gcs)
value: $(params.artifacts-gcs)/artifacts/junit_py-lint
- name: lint-src-dir
value: $(params.lint-src-dir)
resources:
Expand All @@ -35,7 +35,7 @@ spec:
- name: py-test
params:
- name: artifacts-gcs
value: $(params.artifacts-gcs)
value: $(params.artifacts-gcs)/artifacts
- name: test-src-dir
value: $(params.test-src-dir)
resources:
Expand Down
16 changes: 13 additions & 3 deletions py/kubeflow/testing/tekton_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,12 +405,22 @@ def junit_parse_and_upload(artifacts_dir, output_gcs):

for testcase in root:
testname = testcase.attrib.get("name", "unknown-test")
# Detect error and failures from testcase
failed_num += int(testcase.attrib.get(
"errors", "0")) +int(testcase.attrib.get("failures", "0"))
has_failure = False
for failure in testcase:
has_failure = True
logging.error("%s has failure: %s",
testname,
failure.attrib.get("message", "message not found"))
failure_element = failure.find('failure')
if failure_element is not None:
logging.error("%s has failure: %s",
testname,
failure_element.attrib.get("message", "message not found"))
else:
logging.error("%s has failure: %s",
testname,
failure.attrib.get("message", "message not found"))

if not has_failure:
logging.info("%s has passed all the tests.", testname)

Expand Down
6 changes: 1 addition & 5 deletions py/kubeflow/testing/test_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,8 @@ def generate_xml(self):
# want one underscore after junit.
output_file = os.path.join(self.artifacts_dir,
"junit_" + self.name.replace("_", "-") + ".xml")
# junit_xml produces a list of test suites, but gubernator
# only parses a single test suite. So here we generate
# the xml using junit-xml and only output the first test
# suite in our output file
xml_out = junit_xml.TestSuite.to_xml_string([self])
first_test_suite = ET.fromstring(xml_out)[0]
first_test_suite = ET.fromstring(xml_out)
logging.info("Writing file: %s", output_file)
ET.ElementTree(first_test_suite).write(output_file)

Expand Down
4 changes: 2 additions & 2 deletions tekton/templates/pipelines/py-unittests-pipeline.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ spec:
- name: py-lint
params:
- name: artifacts-gcs
value: "$(params.artifacts-gcs)"
value: $(params.artifacts-gcs)/artifacts/junit_py-lint
- name: lint-src-dir
value: "$(params.lint-src-dir)"
resources:
Expand All @@ -37,7 +37,7 @@ spec:
- name: py-test
params:
- name: artifacts-gcs
value: "$(params.artifacts-gcs)"
value: $(params.artifacts-gcs)/artifacts
- name: test-src-dir
value: "$(params.test-src-dir)"
resources:
Expand Down

0 comments on commit f2bbbcd

Please sign in to comment.