-
-
Save wongcyrus/69fdc3ac3b74ef9ec08931022146a4c5 to your computer and use it in GitHub Desktop.
GitHub Classroom autograding tests configure generator - 1 point per pytest test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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