A package for easy autograding.
Project description
Grade: Get Readymade Autograding Done Efficiently
A utility for programming assignment autograding.
Motivation
Grade attempts alleviate typical problems in autograding workflows.
By providing easy-to-use wrappers to work directly with executable files, Grade can test almost anything.
Combining that with the ScoringMixin
and the GradedRunner
, allows you to output your scores for Gradescope or an in-house Markdown report.
Documentation
https://grade.readthedocs.io/en/latest/
Setup
Pip
python -m pip install grade
Docker
FROM thoward27/grade:latest
Quickstart
- Create a
unittest.TestCase
- Optionally, add in the
grade.mixins.ScoringMixin
- For each question, you can use
@grade.decorators.weight(x)
orself.weight = x
to set the weight of a question. - If you wish to assign partial credit for some portion of a test, you can use
self.score = x
. (Warning: if you leave a test with partial credit, the student will receive that score, to give full credit at the end simply runself.score = self.weight
) - Run the tests using
grade.runners.GradedRunner().run(TestSuite)
, which returns aResult
object. - Once you have the results, you can output them to
json
via the propertyresults.json
Gradescope
To properly output scores for Gradescope, simply write the json
results to /autograder/results/results.json
Option 1: Redirection
Given the following python snippet at the end of your test file:
import unittest
from grade.runners import GradedRunner
if __name__ == "__main__":
suite = unittest.TestLoader().discover('./', pattern='test*')
print(GradedRunner().run(suite).json)
Simply redirect the output:
python test.py > autograder/results/results.json
Option 2: Direct Writing
Of course, you can also write directly to the file in your code.
Ensure you only do this in one place, or it may overwrite your work!
import unittest
from grade.runners import GradedRunner
if __name__ == "__main__":
suite = unittest.TestLoader().discover('./', pattern='test*')
results = GradedRunner().run(suite)
with open('/autograder/results/results.json', 'w') as f:
f.write(results.json)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.