Unverified Commit aa5c94d3 authored by Yih-Dar's avatar Yih-Dar Committed by GitHub
Browse files

Show failed tests on CircleCI layout in a better way (#25895)



* update

* update

* fix

---------
Co-authored-by: default avatarydshieh <ydshieh@users.noreply.github.com>
parent 9a70d6e5
...@@ -223,18 +223,27 @@ class CircleCIJob: ...@@ -223,18 +223,27 @@ class CircleCIJob:
# failure. # failure.
test_command = f"({test_command}) || true" test_command = f"({test_command}) || true"
else: else:
test_command += " | tee tests_output.txt" test_command += " || true"
steps.append({"run": {"name": "Run tests", "command": test_command}}) steps.append({"run": {"name": "Run tests", "command": test_command}})
check_test_command = f'if [ -s reports/tests_{self.name}/failures_short.txt ]; '
check_test_command += 'then echo "Some test failed!"; echo ""; '
check_test_command += f'cat reports/tests_{self.name}/failures_short.txt; '
check_test_command += 'echo ""; echo ""; '
py_command = f'import os; fp = open("reports/tests_{self.name}/summary_short.txt"); failed = os.linesep.join([x for x in fp.read().split(os.linesep) if x.startswith("FAILED ")]); fp.close(); fp = open("summary_short.txt", "w"); fp.write(failed); fp.close()'
check_test_command += f"$(python3 -c '{py_command}'); "
check_test_command += f'cat summary_short.txt; echo ""; exit -1; '
check_test_command += f'elif [ -s reports/tests_{self.name}/stats.txt ]; then echo "All tests pass!"; '
# return code `124` means the previous (pytest run) step is timeout # return code `124` means the previous (pytest run) step is timeout
if self.name == "pr_documentation_tests": if self.name == "pr_documentation_tests":
checkout_doctest_command = 'if [ -s reports/tests_pr_documentation_tests/failures_short.txt ]; ' check_test_command += 'elif [ -f 124.txt ]; then echo "doctest timeout!"; '
checkout_doctest_command += 'then echo "some test failed"; '
checkout_doctest_command += 'cat reports/tests_pr_documentation_tests/failures_short.txt; ' check_test_command += 'else echo "other fatal error"; echo ""; exit -1; fi;'
checkout_doctest_command += 'cat reports/tests_pr_documentation_tests/summary_short.txt; exit -1; '
checkout_doctest_command += 'elif [ -s reports/tests_pr_documentation_tests/stats.txt ]; then echo "All tests pass!"; ' steps.append({"run": {"name": "Check test results", "command": check_test_command}})
checkout_doctest_command += 'elif [ -f 124.txt ]; then echo "doctest timeout!"; else echo "other fatal error)"; exit -1; fi;'
steps.append({"run": {"name": "Check doctest results", "command": checkout_doctest_command}})
steps.append({"store_artifacts": {"path": "~/transformers/tests_output.txt"}}) steps.append({"store_artifacts": {"path": "~/transformers/tests_output.txt"}})
steps.append({"store_artifacts": {"path": "~/transformers/reports"}}) steps.append({"store_artifacts": {"path": "~/transformers/reports"}})
...@@ -594,7 +603,7 @@ def create_circleci_config(folder=None): ...@@ -594,7 +603,7 @@ def create_circleci_config(folder=None):
job.tests_to_run = [f"examples/{framework}"] job.tests_to_run = [f"examples/{framework}"]
else: else:
job.tests_to_run = [f for f in example_tests.split(" ") if f.startswith(f"examples/{framework}")] job.tests_to_run = [f for f in example_tests.split(" ") if f.startswith(f"examples/{framework}")]
if len(job.tests_to_run) > 0: if len(job.tests_to_run) > 0:
jobs.append(job) jobs.append(job)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment