|
13 | 13 |
|
14 | 14 | def register_test_class(file_path: str, test_class: typing.ClassVar): |
15 | 15 | subject = test_class.__doc__ |
16 | | - exercise = models.Exercise.get_or_none(models.Exercise.subject == subject) |
17 | | - if not exercise: |
18 | | - log.info(f'Failed to find exercise subject {subject}') |
| 16 | + exercises = tuple( |
| 17 | + models.Exercise.filter(models.Exercise.subject == subject), |
| 18 | + ) |
| 19 | + if not exercises: |
| 20 | + log.info(f'Failed to find exercises for subject {subject}') |
19 | 21 | raise SystemError |
20 | 22 |
|
21 | 23 | with open(file_path, 'r') as file_reader: |
22 | 24 | code = file_reader.read() |
23 | 25 |
|
24 | | - exercise_test = models.ExerciseTest.get_or_create_exercise_test( |
25 | | - exercise=exercise, |
26 | | - code=code, |
27 | | - ) |
| 26 | + for exercise in exercises: |
| 27 | + exercise_test = models.ExerciseTest.get_or_create_exercise_test( |
| 28 | + exercise=exercise, |
| 29 | + code=code, |
| 30 | + ) |
28 | 31 |
|
29 | | - for test_func_name in inspect.getmembers(test_class): |
30 | | - test_func_name = test_func_name[0] |
31 | | - if test_func_name.startswith('test_'): |
32 | | - test_func = getattr(test_class, test_func_name) |
33 | | - models.ExerciseTestName.create_exercise_test_name( |
34 | | - exercise_test=exercise_test, |
35 | | - test_name=test_func_name, |
36 | | - pretty_test_name=test_func.__doc__, |
37 | | - ) |
| 32 | + for test_func_name in inspect.getmembers(test_class): |
| 33 | + test_func_name = test_func_name[0] |
| 34 | + if test_func_name.startswith('test_'): |
| 35 | + test_func = getattr(test_class, test_func_name) |
| 36 | + models.ExerciseTestName.create_exercise_test_name( |
| 37 | + exercise_test=exercise_test, |
| 38 | + test_name=test_func_name, |
| 39 | + pretty_test_name=test_func.__doc__, |
| 40 | + ) |
38 | 41 |
|
39 | 42 |
|
40 | 43 | def load_tests_from_path(file_path: str): |
|
0 commit comments