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
- Add point values to test functions using the
- Test Locking as described in Basu et al., Automated Problem Clarification at Scale (abstract, pdf)
- Lock doctests using the
# LOCKcomment before the function. pytest-grader lock [src] [dst]will generate a copy of src with doctests locked.pytest --unlockprovides an interactive interface for unlocking locked doctests.- A doctest whose output is a function should give
FUNCTIONas the expected output, which matches any function value. When unlocking, typeFUNCTIONfor such outputs.
- Lock doctests using the
- Test Isolation
- Modules listed under
reload_modulesingrader.yamlare 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.
- Modules listed under
- Progress Logging
- Each pytest session is recorded in a
grader.sqlitedatabase: the pytest command (pytestplus 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.
- Each pytest session is recorded in a
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
Updating versions
- Change version in
pyproject.toml uv builduv publishIf your pypi credentials are in~/.pypirc, then instead runuvx uv-publish.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
pytest_grader-0.1.8.tar.gz
(16.6 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pytest_grader-0.1.8.tar.gz.
File metadata
- Download URL: pytest_grader-0.1.8.tar.gz
- Upload date:
- Size: 16.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
625faeb32fbfa7c94c2ae2683c112c62c218ffa124522acc7feca7e020fea8ea
|
|
| MD5 |
090af3b708110b59b92e640e390d3127
|
|
| BLAKE2b-256 |
f5d704ccf01ca5a013e29b6cfb05eccc10194d48aa4ca4b207de33a7a172d7f8
|
File details
Details for the file pytest_grader-0.1.8-py3-none-any.whl.
File metadata
- Download URL: pytest_grader-0.1.8-py3-none-any.whl
- Upload date:
- Size: 13.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a5156d27c8d61c4e927abc942859daa10a2c7f2ebf102a707f16b05b0d26b39d
|
|
| MD5 |
1a2dab37a5f7de6bcb46558c36354a19
|
|
| BLAKE2b-256 |
ef64a4dfc4eaa2939fc96ac8b7a17652926f08f05b71efb083c1db369a310dbc
|