Skip to main content

pytest-grader

A pytest plugin for testing and scoring programming assignments.

Features

  • Assignment Scoring
    • Add point values to test functions using the @points(n) decorator
    • Show a score summary when running pytest --score
  • Test Locking as described in Basu et al., Automated Problem Clarification at Scale (abstract, pdf)
    • Lock doctests using the # LOCK comment before the function.
    • pytest-grader lock [src] [dst] will generate a copy of src with doctests locked.
    • pytest --unlock provides an interactive interface for unlocking locked doctests.
    • A doctest whose output is a function should give FUNCTION as the expected output, which matches any function value. When unlocking, type FUNCTION for such outputs.
  • Test Isolation
    • Modules listed under reload_modules in grader.yaml are reloaded before each test, so a test that mutates a module (e.g. by monkeypatching one of its functions) does not affect later tests.
    • Globals injected by pytest's assertion rewriting (@py_builtins, @pytest_ar) are removed from doctest namespaces.
  • Progress Logging
    • Each pytest session is recorded in a grader.sqlite database: the pytest command (pytest plus the arguments pytest received, however it was launched), a timestamp, and snapshots of the assignment files at that time.
    • Test case results and unlocking attempts are stored there as well, linked to their session's snapshot.
    • This file is designed to be submitted along with the assignment as a record of how the assignment was completed.

Usage

Include a conftest.py file in the distribution of your assignment that contains pytest_plugins = ["pytest_grader"].

Describe the assignment in a grader.yaml file next to it:

included_files:   # Files snapshotted into grader.sqlite when tests run
  - hog.py
reload_modules:   # Modules reloaded before each test for isolation
  - hog

See the examples directory for more usage info.

License

MIT

Updating versions

  • Change version in pyproject.toml
  • uv build
  • uv publish If your pypi credentials are in ~/.pypirc, then instead run uvx uv-publish.

Metadata

Release files for pytest-grader 0.1.9

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-grader 0.1.9
File Size Uploaded
pytest_grader-0.1.9.tar.gz 17.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pytest-grader 0.1.9
File Interpreter ABI Platform
pytest_grader-0.1.9-py3-none-any.whl Python 3 none any Details

Total release size: 30.2 kB

Release files / pytest_grader-0.1.9.tar.gz

Download URL pytest_grader-0.1.9.tar.gz
Size 17.0 kB
Tags Source
SHA-256 checksum
How to use checksums
c692b9ae44ef96bc9cb07d8b76620220ada9eec1d0d73b3c1e0a3eabc1d0f5b5
BLAKE2b-256 checksum
How to use checksums
6d1d7919fcd1693df14b30dcaea6739bc7ded8d04b65b2f4bc3dd59973bfb51b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.7.13

Release files / pytest_grader-0.1.9-py3-none-any.whl

Download URL pytest_grader-0.1.9-py3-none-any.whl
Size 13.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d2a833dd3bb9a4671f9d0c2b95111f6cf952758d014088aacdf760d17753f33f
BLAKE2b-256 checksum
How to use checksums
3f500924072bac3cc9cf927af7ab6eab4534ae1b077d83896457de6c4b69d06f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.7.13

Release history Release notifications | RSS feed

0.4.0

2 release files

0.3.3

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.10

2 release files

This release

0.1.9 This release

2 release files

0.1.8

2 release files

0.1.7

2 release files

0.1.6

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

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