Pytest extension for scoring programming assignments.
Project description
pytest-grader
A pytest plugin for scoring programming assignments with points-based grading.
Features
- Add point values to test functions using the
@points(n)decorator - Show a score summmary when running
pytest --score - TODO Lock doctests using the
@lockdecorator. - TODO
python3 pytest-grader --lock [src] [dest]will generate a copy of src with doctests locked.
Use
The recommended way to use this pytest plugin is to include pytest-grader in the ...
It is also possible to install this with:
pip install pytest-grader
Usage
Basic Example
from pytest_grader import points
def square(x):
return x * x
@points(3)
def test_square_int():
assert square(3) == 9
assert square(-4) == 16
@points(2)
def test_square_float():
assert square(0.5) == 0.25
Configuration
Add to your conftest.py:
pytest_plugins = ["pytest_grader"]
How It Works
- Decoration: Use
@points(n)to assign point values to test functions - Collection: The plugin automatically detects tests with point values during collection
- Execution: Tests run normally with pytest
- Scoring: Points are awarded for passing tests, zero for failing tests
- Summary: A formatted grade report is displayed after all tests complete
Sample Output
PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP
test_square_int 3/3 pts
test_square_float 2/2 pts
L test_twice_function 0/4 pts
\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00
Total Score: 5/9 pts (55.6%)
Perfect scores display with special formatting:
(Total Score: 9/9 pts (=�%)(
Requirements
- Python >= 3.10
- pytest >= 8
License
This project is licensed under the MIT License.
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
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.0.tar.gz.
File metadata
- Download URL: pytest_grader-0.1.0.tar.gz
- Upload date:
- Size: 2.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e17ec29bcce62a185bd161d2e171ff0c8ec27a637b2107c334f7f9775c22360e
|
|
| MD5 |
34573958ad99f427919818f0a7a6989a
|
|
| BLAKE2b-256 |
4f2fb8bd41d99a25c3be082601efe628b197ca3cb7d53c2ddff5e8ab6632f4e6
|
File details
Details for the file pytest_grader-0.1.0-py3-none-any.whl.
File metadata
- Download URL: pytest_grader-0.1.0-py3-none-any.whl
- Upload date:
- Size: 3.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ccf8fe46b465dfd03d7c915aaec34712b73399b4813025447fd1a727fe2b0150
|
|
| MD5 |
fe529681f4ba5b64209a734c13702e58
|
|
| BLAKE2b-256 |
b0478d63394d68ff35d319c3295265798dd9ecadbae91d8c0351544e8b03c4ad
|