Skip to content

Commit 0befbe9

Browse files
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 <hassan@hassanamr.com>
1 parent 28b6d4c commit 0befbe9

2 files changed

Lines changed: 9 additions & 7 deletions

File tree

backend/routes/forms/unittesting.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,14 @@ def _make_unit_code(units: dict[str, str]) -> str:
3636
result = ""
3737

3838
for unit_name, unit_code in units.items():
39-
test_prefix = "test_" if unit_name != "setUp" else ""
40-
41-
result += (
42-
f"\ndef {test_prefix}{unit_name.removeprefix('#')}(self):" # Function definition
43-
f"\n{indent(unit_code, ' ')}" # Unit code
44-
)
39+
# Function definition
40+
if unit_name == "setUp":
41+
result += "\ndef setUp(self):"
42+
else:
43+
result += f"\nasync def {unit_name.removeprefix('#')}(self):"
44+
45+
# Unite code
46+
result += f"\n{indent(unit_code, ' ')}"
4547

4648
return indent(result, " ")
4749

resources/unittest_template.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
### USER CODE
1616

1717

18-
class RunnerTestCase(unittest.TestCase):
18+
class RunnerTestCase(unittest.IsolatedAsyncioTestCase):
1919
### UNIT CODE
2020

2121

0 commit comments

Comments
 (0)