Skip to main content

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 @lock decorator.
  • 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

  1. Decoration: Use @points(n) to assign point values to test functions
  2. Collection: The plugin automatically detects tests with point values during collection
  3. Execution: Tests run normally with pytest
  4. Scoring: Points are awarded for passing tests, zero for failing tests
  5. 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

pytest_grader-0.1.0.tar.gz (2.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pytest_grader-0.1.0-py3-none-any.whl (3.2 kB view details)

Uploaded Python 3

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

Hashes for pytest_grader-0.1.0.tar.gz
Algorithm Hash digest
SHA256 e17ec29bcce62a185bd161d2e171ff0c8ec27a637b2107c334f7f9775c22360e
MD5 34573958ad99f427919818f0a7a6989a
BLAKE2b-256 4f2fb8bd41d99a25c3be082601efe628b197ca3cb7d53c2ddff5e8ab6632f4e6

See more details on using hashes here.

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

Hashes for pytest_grader-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ccf8fe46b465dfd03d7c915aaec34712b73399b4813025447fd1a727fe2b0150
MD5 fe529681f4ba5b64209a734c13702e58
BLAKE2b-256 b0478d63394d68ff35d319c3295265798dd9ecadbae91d8c0351544e8b03c4ad

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page