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. - Unlocked outputs are saved in
.unlocked.json(see--unlock-file) so that tests stay unlocked across pytest runs.
- Lock doctests using the
- Test Isolation
- Modules listed under
reload_modulesingrader.jsonare 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
Usage
Include a conftest.py file in the distribution of your assignment that contains pytest_plugins = ["pytest_grader"].
Optionally describe the assignment in a grader.json file next to it:
{
"reload_modules": ["hog"]
}
reload_modules lists modules reloaded before each test for isolation.
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.2.0
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.2.0.tar.gz | 15.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pytest_grader-0.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 26.8 kB
Release files / pytest_grader-0.2.0.tar.gz
| Download URL | pytest_grader-0.2.0.tar.gz |
|---|---|
| Size | 15.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
48566d65b5cc3a338cc5771fda28148ca1aad24a96abf81026e7d427c978597e
|
|
BLAKE2b-256 checksum How to use checksums |
9158422979dd33e9aa20e4769369ed3bd30b238f02ff41061a688dac13d1f31f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.7.13
|
Release files / pytest_grader-0.2.0-py3-none-any.whl
| Download URL | pytest_grader-0.2.0-py3-none-any.whl |
|---|---|
| Size | 11.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d6ace3f36b599e6b31ff3b2310f3c3917b88f3e5267cbd9a6346e93b60834ed1
|
|
BLAKE2b-256 checksum How to use checksums |
ed68d2c834e4ea12d5ac493b1ecf2b8b30cb15ad96cb600a4390b009270996dd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.7.13
|