Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Figured out how to pass parameters from settings #36

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
28 changes: 21 additions & 7 deletions gradescope_utils/autograder_utils/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,16 +82,30 @@ Example output:
```

### GradescopeDjangoRunner
This allows for an integration between Django testing, which utilizes unittest and
Gradescope's JSONTestRunner to obtain the JSON output of the Django test cases.
This allows for an integration between Django testing, which utilizes unittest and Gradescope's JSONTestRunner to obtain the JSON output of the Django test cases.

To enable this, complete the following steps:

First, in your settings.py, insert the line:
```
`TEST_RUNNER = 'gradescope_utils.autograder_utils.gradescope_django_runner.GradescopeDjangoRunner'`
* The `GRADESCOPE_PARAMETERS` is used to set different arguments for the JSONTestRunner from the default ones. In your settings.py, insert the lines below:
```python
import sys

TEST_RUNNER = 'gradescope_utils.autograder_utils.gradescope_django_runner.GradescopeDjangoRunner'

GRADESCOPE_PARAMETERS = {
'stream': sys.stdout,
'descriptions': True,
'verbosity': 1,
'failfast': False,
'buffer': True,
'visibility': "visible",
'stdout_visibility': None,
'post_processor': None,
'failure_prefix': "Test Failed: "
}
```

Then, within your `run_autograder`, run the following command:
* You can either pass a file descriptor to `/autograder/results/results.json` as an argument to `'stream'` in the `GRADESCOPE_PARAMETERS`. Alternatively, within your `run_autograder`, run the following command:
```
python3 manage.py test -v 0 > /autograder/results/results.json
```
```
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import sys
from django.test.runner import DiscoverRunner
from gradescope_utils.autograder_utils.json_test_runner import JSONTestRunner
from django.test.runner import DiscoverRunner
from django.conf import settings


class GradescopeDjangoRunner(DiscoverRunner):
"""Replacing Django Default Unit Test Runner with Gradescope Test Runner"""

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
parameters = getattr(settings, "GRADESCOPE_PARAMETERS", {})
self.test_runner = JSONTestRunner(**parameters)

def run_suite(self, suite, **kwargs):
return JSONTestRunner(**kwargs).run(suite)
return self.test_runner.run(suite)