diff options
Diffstat (limited to 'backend/routes/forms/unittesting.py')
-rw-r--r-- | backend/routes/forms/unittesting.py | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/backend/routes/forms/unittesting.py b/backend/routes/forms/unittesting.py index a830775..13fa639 100644 --- a/backend/routes/forms/unittesting.py +++ b/backend/routes/forms/unittesting.py @@ -36,10 +36,14 @@ def _make_unit_code(units: dict[str, str]) -> str: result = "" for unit_name, unit_code in units.items(): - result += ( - f"\ndef test_{unit_name.lstrip('#')}(unit):" # Function definition - f"\n{indent(unit_code, ' ')}" # Unit code - ) + # Function definition + if unit_name == "setUp": + result += "\ndef setUp(self):" + else: + result += f"\nasync def {unit_name.removeprefix('#')}(self):" + + # Unite code + result += f"\n{indent(unit_code, ' ')}" return indent(result, " ") @@ -83,7 +87,7 @@ async def execute_unittest(form_response: FormResponse, form: Form) -> list[Unit # Tests starting with an hashtag should have censored names. hidden_test_counter = count(1) hidden_tests = { - test.lstrip("#").lstrip("test_"): next(hidden_test_counter) + test.removeprefix("#").removeprefix("test_"): next(hidden_test_counter) for test in question.data["unittests"]["tests"].keys() if test.startswith("#") } |