cg-pytest-reporter
A Pytest reporter plugin for CodeGrade AutoTest v2.
This plugin writes messages to CodeGrade AutoTest v2's structured output channel.
For each test that was run a unit-test message is written as described in
CodeGrade's documentation. When all tests have finished running, a final message
is written with the amount of points that were achieved in the test run.
Utility functions
This plugin comes with a few utility functions to easily modify certain aspects of each test case or test suite. All of these are decorators that you can apply directly to your test functions or classes.
Test suite decorators
These decorators change properties of an entire test suite. In terms of Pytest that is a single file containing test functions, or a single class within such a file.
suite_name
With the suite_name you can modify the name of a test suite that will be
displayed in the AutoTest v2 UI.
from cg_pytest_reporter import suite_name
@suite_name('My Test Suite')
class TestSuite:
def test_function():
assert True
Because it is not possible to decorate an entire module, it is possible to
change the name of the module-level suite by setting the __cg_suite_name__
variable on the module.
__cg_suite_name__ = 'My Test Suite'
def test_function():
assert True
suite_weight
Use the suite_weight decorator to change the weight of an entire suite
relative to other suites in your test run.
You can use strings, integers, floats and fractions.Fraction as weight. For the best precision strings, integers and fractions are recommended.
from cg_pytest_reporter import suite_weight
@suite_weight('2.1')
class TestSuite:
def test_function():
assert True
Similar to the suite name, you can set the weight of the module-level suite with
the __cg_suite_weight__ variable.
import fractions
__cg_suite_weight__ = fractions.Fraction(2, 1)
# Or:
# __cg_suite_weight__ = 2
def test_function():
assert True
Test function decorators
These decorators modify the behaviour of a single test case.
Although they work on the test case level, they can be applied to a class containing test functions. This works as if the decorator was applied to each test function individually, but each decorator can still be overridden on individual test cases. It is mentioned on each of the decorators where this might be useful.
name
With the name decorator you can change the name of a single test case.
from cg_pytest_reporter import name
@name('My Cool Test')
def test_function():
assert True
description
With the description decorator you can set a description for a single test
case. This can be useful if the name of the test function is not descriptive
enough.
from cg_pytest_reporter import description
@description('A somewhat longer description of what is being tested.')
def test_function():
assert True
weight
Change the weight of a single test function relative to other test functions within the same suite.
You can use strings, integers, floats and fractions.Fraction as weight. For the best precision strings, integers and fractions are recommended.
from cg_pytest_reporter import weight
@weight(2)
def test_function():
assert True
This decorator can also be applied to a test class, in which case it will set a default weight for all tests within that class which can still be overridden for individual tests within that class. This can be useful for example if you want most tests within a class not to count towards the score.
from cg_pytest_reporter import weight
@weight(0)
class TestClass:
# This test case will have a weight of 0 applied, and as such will not count
# towards the achieved score.
def test_function():
assert True
# This test case will still count towards the score with the default weight
# of 1.
@weight(1)
def test_something_else():
assert True
reason
Change the reason of failure of the test case. This can be used to give students a hint where their code is likely to break.
from cg_pytest_reporter import reason
from fibonacci import fibonacci
@reason('Did you start counting at the correct index? (off-by-one error)')
def test_fibonacci():
assert fibonacci(10) == 55
hide_stdout
When a test fails, the stdout that was written while the test was running is
sent along with the result. With the hide_stdout decorator you can prevent the
stdout from being sent.
from cg_pytest_reporter import hide_stdout
# The string "Hello World!" that was printed to `stdout` will not be sent along
# with the results.
@hide_stdout
def test_failure():
print('Hello World!')
assert False
This decorator can also be applied to a test class to hide the stdout of each
test case within it.
from cg_pytest_reporter import hide_stdout
@hide_stdout
class TestClass:
def test_failure():
print('Hello World!')
assert False
def test_ok():
print('Hello World!')
hide_stderr
This works the same as hide_stdout except that it will hide the stderr
channel instead.
import sys
from cg_pytest_reporter import hide_stderr
# The string "Hello World!" that was printed to `stderr` will not be sent along
# with the results.
@hide_stderr
def test_failure():
print('Hello World!', file=sys.stderr)
assert False
This decorator can also be applied to a test class to hide the stderr of each
test case within it.
import sys
from cg_pytest_reporter import hide_stderr
@hide_stderr
class TestClass:
def test_failure():
print('Hello World!', file=sys.stderr)
assert False
def test_ok():
print('Hello World!', file=sys.stderr)
hide_output
A combined version of hide_stdout and hide_stderr.
import sys
from cg_pytest_reporter import hide_output
# The string "Hello World!" that was printed to `stdout` or `stderr` will not be
# sent along with the results.
@hide_output
def test_failure():
print('Hello World!')
print('Hello World!', file=sys.stderr)
assert False
This decorator can also be applied to a test class to hide the output of each test case within it.
import sys
from cg_pytest_reporter import hide_output
@hide_output
class TestClass:
def test_failure():
print('Hello World!', file=sys.stderr)
assert False
def test_ok():
print('Hello World!')
Metadata
Release files for cg-pytest-reporter 1!1.1.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| cg_pytest_reporter-1!1.1.3.tar.gz | 8.3 kB | With provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| cg_pytest_reporter-1!1.1.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 16.5 kB
Release files / cg_pytest_reporter-1!1.1.3.tar.gz
| Download URL | cg_pytest_reporter-1!1.1.3.tar.gz |
|---|---|
| Size | 8.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
bc164f51dfd629a5488fd0397faaf7f425ac634acc1cf99d5d20e925d8a58859
|
|
BLAKE2b-256 checksum How to use checksums |
3b0d6cb239a37f0b16e40601deb2331132908ee6d72e3ac52215f02217844ea2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jan 19, 2026.
Transparency logRelease files / cg_pytest_reporter-1!1.1.3-py3-none-any.whl
| Download URL | cg_pytest_reporter-1!1.1.3-py3-none-any.whl |
|---|---|
| Size | 8.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
381b754c1e3d823fc0872f29f0c27864f293508fd8331f9545cb8bf8ee792198
|
|
BLAKE2b-256 checksum How to use checksums |
d4bb6e64cc185c7e266e093f8f524e2fa743036e550ebef848323900e0887179
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jan 19, 2026.
Transparency logSecurity for cg-pytest-reporter 1!1.1.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for cg_pytest_reporter-1!1.1.3.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jan 19, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.