aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Matteo Bertucci <[email protected]>2021-02-24 15:44:37 +0100
committerGravatar Matteo Bertucci <[email protected]>2021-02-24 15:44:37 +0100
commitd466b8016c9fb5a5f23731d83254b0b94cf02990 (patch)
treeb0521644bafce447aa7f3d4ffe61a4ed6c3f22f4
parentMove most of the unittest template inside of the handler (diff)
Properly handle return codes 5 and 99
-rw-r--r--backend/routes/forms/unittesting.py32
1 files changed, 18 insertions, 14 deletions
diff --git a/backend/routes/forms/unittesting.py b/backend/routes/forms/unittesting.py
index e038f3a..f7f6072 100644
--- a/backend/routes/forms/unittesting.py
+++ b/backend/routes/forms/unittesting.py
@@ -102,21 +102,25 @@ async def execute_unittest(form_response: FormResponse, form: Form) -> list[Unit
return_code = 99
result = "Internal error."
else:
- stdout = response["stdout"]
- passed = bool(int(stdout[0]))
-
- # If the test failed, we have to populate the result string.
- if not passed:
- failed_tests = stdout[1:].strip().split(";")
-
- # Redact failed hidden tests
- for i, failed_test in enumerate(failed_tests[:]):
- if failed_test in hidden_tests:
- failed_tests[i] = f"hidden_test_{hidden_tests[failed_test]}"
-
- result = ";".join(failed_tests)
+ # Parse the stdout if the tests ran successfully
+ if return_code == 0:
+ stdout = response["stdout"]
+ passed = bool(int(stdout[0]))
+
+ # If the test failed, we have to populate the result string.
+ if not passed:
+ failed_tests = stdout[1:].strip().split(";")
+
+ # Redact failed hidden tests
+ for i, failed_test in enumerate(failed_tests[:]):
+ if failed_test in hidden_tests:
+ failed_tests[i] = f"hidden_test_{hidden_tests[failed_test]}"
+
+ result = ";".join(failed_tests)
+ else:
+ result = ""
else:
- result = ""
+ result = response["stdout"]
unittest_results.append(UnittestResult(
question_id=question.id,