Skip to main content

A pytest plugin for Gradescope integration

Project description

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")

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pytest_gradescope-0.1.6.tar.gz (4.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pytest_gradescope-0.1.6-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

Details for the file pytest_gradescope-0.1.6.tar.gz.

File metadata

  • Download URL: pytest_gradescope-0.1.6.tar.gz
  • Upload date:
  • Size: 4.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for pytest_gradescope-0.1.6.tar.gz
Algorithm Hash digest
SHA256 6a5cef504c91256ab7c70797f3f6b16958178cddba8ddf19d03d8001e555328c
MD5 0304f65d8ac58597f2c052317463bcea
BLAKE2b-256 0c2eb53314bb216cb6566171c22bfe0d30095f571e045ef2197c2bb02fe35b09

See more details on using hashes here.

File details

Details for the file pytest_gradescope-0.1.6-py3-none-any.whl.

File metadata

File hashes

Hashes for pytest_gradescope-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 2e12ec6dd32c415da9f6a5ed2ea7629332251515dea325dc68c686c881bd30d5
MD5 1529e4002c4328da00a63267bbccdf44
BLAKE2b-256 571544eab2b648d21eadc04f0c51d9ef3b81bafc7ce5ccf43f659ddf0601a2a2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page