Skip to content

Instantly share code, notes, and snippets.

@wongcyrus
Created July 22, 2022 08:18
Show Gist options
  • Save wongcyrus/69fdc3ac3b74ef9ec08931022146a4c5 to your computer and use it in GitHub Desktop.
Save wongcyrus/69fdc3ac3b74ef9ec08931022146a4c5 to your computer and use it in GitHub Desktop.
GitHub Classroom autograding tests configure generator - 1 point per pytest test
import sys
import json
import pytest
tests = []
class MyPlugin:
def pytest_itemcollected(self, item):
print(item.nodeid)
tests.append(item.nodeid)
if __name__ == "__main__":
return_code = pytest.main([], plugins=[MyPlugin()])
assignments = list(map(lambda x: {
"name": x.split('/')[2],
"setup": "sudo -H pip3 install pytest",
"run": "pytest -x " + x,
"input": "",
"output": "",
"comparison": "included",
"timeout": 10,
"points": 1
}, tests))
assignments = {"tests": assignments}
# print(assignments)
json_string = json.dumps(assignments)
with open('autograding.json', 'w') as outfile:
outfile.write(json_string)
sys.exit(return_code)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment