Skip to content

Commit d79fe89

Browse files
committed
ISSUE-662: Return extra_marks as submission object rather than individual test object
1 parent 7e26f78 commit d79fe89

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

server/autotest_server/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ def _create_test_group_result(
8383
result["annotations"] = res["annotations"]
8484
elif "tags" in res:
8585
result["tags"] = res["tags"]
86+
elif "extra_marks" in res:
87+
result["extra_marks"] = res["extra_marks"]
8688
elif "overall_comment" in res:
8789
result["overall_comment"] = res["overall_comment"]
8890
else:

server/autotest_server/testers/py/py_tester.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ def __init__(self) -> None:
103103
self.results = {}
104104
self.tags = set()
105105
self.annotations = []
106+
self.extra_marks = {}
106107
self.overall_comments = []
107108

108109
def pytest_configure(self, config):
@@ -181,18 +182,18 @@ def _process_markers(self, item):
181182
self.results[item.nodeid]["marks_earned"] = marker.args[0]
182183
elif marker.name == "markus_extra_marks" and marker.args != [] and item.nodeid in self.results:
183184
self.results[item.nodeid]["marks_earned"] += marker.args[0]
184-
bonus_comment = {
185+
extra_mark = {
185186
"id": str(uuid.uuid4()),
186187
"mark": marker.args[0],
187188
"fn": item.nodeid,
188189
"description": marker.args[1],
189190
"unit": marker.args[2] if len(marker.args) > 2 else "points",
190191
}
191192

192-
if self.results[item.nodeid].get("bonus_comments"):
193-
self.results[item.nodeid]["bonus_comments"].append(bonus_comment)
193+
if self.extra_marks.get(item.nodeid):
194+
self.extra_marks[item.nodeid].append(extra_mark)
194195
else:
195-
self.results[item.nodeid]["bonus_comments"] = [bonus_comment]
196+
self.extra_marks[item.nodeid] = [extra_mark]
196197

197198
def pytest_collectreport(self, report):
198199
"""
@@ -282,6 +283,7 @@ def __init__(
282283
"""
283284
super().__init__(specs, test_class, resource_settings=resource_settings)
284285
self.annotations = []
286+
self.extra_marks = {}
285287
self.overall_comments = []
286288
self.tags = set()
287289

@@ -326,6 +328,7 @@ def _run_pytest_tests(self, test_file: str) -> List[Dict]:
326328
results.extend(plugin.results.values())
327329
self.annotations = plugin.annotations
328330
self.overall_comments = plugin.overall_comments
331+
self.extra_marks = plugin.extra_marks
329332
self.tags = plugin.tags
330333
finally:
331334
sys.stdout = sys.__stdout__
@@ -363,3 +366,5 @@ def after_tester_run(self) -> None:
363366
print(self.test_class.format_tags(self.tags))
364367
if self.overall_comments:
365368
print(self.test_class.format_overall_comment(self.overall_comments, separator="\n\n"))
369+
if self.extra_marks:
370+
print(self.test_class.format_extra_marks(self.extra_marks))

server/autotest_server/testers/tester.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,15 @@ def format_overall_comment(overall_comment_data: str | Iterable[str], separator:
110110
content = separator.join(overall_comment_data)
111111
return json.dumps({"overall_comment": content})
112112

113+
@staticmethod
114+
def format_extra_marks(extra_marks: Dict[str, Any]) -> str:
115+
"""
116+
Formats extra marks data.
117+
:param extra_marks: the contents of the extra marks
118+
:return a json string representation of the extra marks data.
119+
"""
120+
return json.dumps({"extra_marks": extra_marks})
121+
113122
@staticmethod
114123
def format_tags(tag_data: Iterable[str | dict[str, str]]) -> str:
115124
"""

0 commit comments

Comments
 (0)