From 0befbe9f083751e9c195faea1ef1062fbf6dc447 Mon Sep 17 00:00:00 2001 From: Hassan Abouelela Date: Fri, 24 Jun 2022 05:45:10 +0400 Subject: Make Unittests Async The codejam test suite uses async functions, which would be annoying to deal with in our current template. Switching to async makes that available to those who want it, without affecting those who don't. Signed-off-by: Hassan Abouelela --- backend/routes/forms/unittesting.py | 14 ++++++++------ resources/unittest_template.py | 2 +- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/backend/routes/forms/unittesting.py b/backend/routes/forms/unittesting.py index c093718..13fa639 100644 --- a/backend/routes/forms/unittesting.py +++ b/backend/routes/forms/unittesting.py @@ -36,12 +36,14 @@ def _make_unit_code(units: dict[str, str]) -> str: result = "" for unit_name, unit_code in units.items(): - test_prefix = "test_" if unit_name != "setUp" else "" - - result += ( - f"\ndef {test_prefix}{unit_name.removeprefix('#')}(self):" # 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, " ") diff --git a/resources/unittest_template.py b/resources/unittest_template.py index 6f704f3..104b3b4 100644 --- a/resources/unittest_template.py +++ b/resources/unittest_template.py @@ -15,7 +15,7 @@ from unittest import mock ### USER CODE -class RunnerTestCase(unittest.TestCase): +class RunnerTestCase(unittest.IsolatedAsyncioTestCase): ### UNIT CODE -- cgit v1.2.3