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. - A doctest that raises an exception should give
ERRORas its entire expected output, which matches any raised exception (and fails if none is raised). - A doctest statement that displays nothing (e.g.
lst.append(2)) may giveNOTHINGas its expected output, so that unlocking still asks about it. - When unlocking, sentinel answers (
FUNCTION,ERROR,NOTHING) may be typed in any case.
- 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.
Metadata
Release files for pytest-grader 0.1.10
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pytest_grader-0.1.10.tar.gz | 17.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pytest_grader-0.1.10-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 31.6 kB
Release files / pytest_grader-0.1.10.tar.gz
| Download URL | pytest_grader-0.1.10.tar.gz |
|---|---|
| Size | 17.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
33178f4201b4b9e5d3ba7ef97115bdcc162dc8d15a2019a8b09b00458536f0cd
|
|
BLAKE2b-256 checksum How to use checksums |
037c924e91f20f82d86484e410a3ffa0b140446325a5728ee0683a1650624ffe
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.7.13
|
Release files / pytest_grader-0.1.10-py3-none-any.whl
| Download URL | pytest_grader-0.1.10-py3-none-any.whl |
|---|---|
| Size | 13.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e83536cd40b4f1739e347c488de7731588181e70b422a729b7e05031da74e885
|
|
BLAKE2b-256 checksum How to use checksums |
6986cff73a2ff041178e9ef773c5f9fd16591c963b13eccfd51ae282b468e062
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.7.13
|