Skip to main content

Gradescope Pytest Library

A package for producing Gradescope-compatible results.json files with Pytest tests.

Forked from ucsb-gradescope-tools/pytest_utils to bring it to parity with the latest version of the Gradescope Python Autograder (which uses unittest).

Usage

At the top of the file where you define your tests, put:

import pytest_gradescope
from pytest_gradescope.decorators import weight, visibility, tags, ...

Then annotate your tests using the provided decorators.

weight

To set the weight for a test:

@weight(value)
def test_a():

Where value is a numeric value.

number

To optionally set the number for a test (used for ordering on Gradescope):

@number(value)
def test_a():

Where value is a numeric value.

visibility

To optionally set the visibility of a test:

@visibility(value)
def test_a():

Where value is 'visible', 'hidden', 'after_due_date', or 'after_published.' Default value is 'visible.'

hide_errors

To optionally hide the errors for a test:

@hide_errors(msg)
def test_a():

Where msg is a message to display instead of the error. Default value is 'Test failed'.

tags

To optionally add extra tags to a test:

@tags(value)
def test_a():

Where value is a string array. Default value is an empty array.

leaderboard

To optionally set the leaderboard for a test:

@leaderboard(column_name, sort_order="desc")
def test_a(set_leaderboard_value = None):
    set_leaderboard_value(value)

Where column_name is the name of the leaderboard column and sort_order is either 'asc' or 'desc', and set_leaderboard_value is a function that can be called to set the value for the leaderboard. If set_leaderboard_value is not called, the test will not contribute to the leaderboard.

partial_credit

To optionally set partial credit for a test:

@partial_credit(weight)
def test_a(set_score=None):
    set_score(partial_score)

Where weight is the weight of the test and set_score is a function that can be called to set the score for the test. If set_score is not called, the test will receive full credit if it passes, or no credit if it fails.

Running Locally

To run locally:

> git clone https://github.com/ucsb-gradescope-tools/pytest_utils.git
> cd pytest_utils
> pip3 install -e .

Then, in the directory where your test_assignment.py lives:

> pytest

The results will be written to results.json.

Example

The assignment is to create a file called assignment.py with a function hello() which returns "hello". The test_assignment.py file is:

import pytest_utils
from pytest_utils.decorators import weight, visibility, tags
from assignment import *

class TestAssignment(object):
    @weight(10)
    def test_one(self):
        assert(hello() == "hello")

Metadata

Release files for pytest-gradescope 0.1.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pytest-gradescope 0.1.6
File Size Uploaded
pytest_gradescope-0.1.6.tar.gz 4.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pytest-gradescope 0.1.6
File Interpreter ABI Platform
pytest_gradescope-0.1.6-py3-none-any.whl Python 3 none any Details

Total release size: 9.4 kB

Release files / pytest_gradescope-0.1.6.tar.gz

Download URL pytest_gradescope-0.1.6.tar.gz
Size 4.3 kB
Tags Source
SHA-256 checksum
How to use checksums
6a5cef504c91256ab7c70797f3f6b16958178cddba8ddf19d03d8001e555328c
BLAKE2b-256 checksum
How to use checksums
0c2eb53314bb216cb6566171c22bfe0d30095f571e045ef2197c2bb02fe35b09
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.3

Release files / pytest_gradescope-0.1.6-py3-none-any.whl

Download URL pytest_gradescope-0.1.6-py3-none-any.whl
Size 5.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2e12ec6dd32c415da9f6a5ed2ea7629332251515dea325dc68c686c881bd30d5
BLAKE2b-256 checksum
How to use checksums
571544eab2b648d21eadc04f0c51d9ef3b81bafc7ce5ccf43f659ddf0601a2a2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.3

Release history Release notifications | RSS feed

This release

0.1.6 This release

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page