Skip to main content

nbgrader_unittest

Drop-in replacement for the unittest module to use them in tests for nbgrader assignments.

You can use this module just like the unittest module. Just don't call the main function to run the tests. Use the run_nbgrader_test function instead.

If your tests all pass, no output will be generated and nbgrader will assign full marks to this cell. If one of your tests fail, the usual unittest output will be created and printed to sys.stderr and no marks will be assigned to this cell in nbgrader.

Example

You prepare a new jupyter notebook assignment with parts, that should be autograded with nbgrader.Your assignment could be something like this:

Write a function that returns a list of numbers, such that $x_i=i^2$, for $1 \leq i \leq n$. Make sure it handles the case where $n<1$ by raising a ValueError.

Your code cell with the "Autograded answer" will look like this:

def squares(n):
    """Compute the squares of numbers from 1 to n, such that the 
    ith element of the returned list equals i^2.
    
    """
    ### BEGIN SOLUTION
    if n < 1:
        raise ValueError("n must be greater than or equal to 1")
    return [x**2 for x in range(1, n + 1)]
    ### END SOLUTION

In a new code cell you put your "Autograder test":

import nbgrader_unittest

class SquaresTests(nbgrader_unittest.TestCase):

    def test_square_of_one(self):
        self.assertEqual(squares(1), [1])
   
    def test_squares_up_to_ten(self):
       self.assertEqual(
           squares(10),
           [1, 4, 9, 16, 25, 36, 49, 64, 81, 100]
       )

    def test_negative_argument(self):
        with self.assertRaises(ValueError):
            squares(-4)

nbgrader_unittest.run_nbgrader_test(SquaresTests)

Metadata

Release files for nbgrader-unittest-sebastian-stigler 0.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for nbgrader-unittest-sebastian-stigler 0.0.3
File Size Uploaded Provenance Actions
nbgrader_unittest_sebastian_stigler-0.0.3.tar.gz 3.3 kB Without provenance Details for nbgrader_unittest_sebastian_stigler-0.0.3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for nbgrader-unittest-sebastian-stigler 0.0.3
File Interpreter ABI Platform Actions
nbgrader_unittest_sebastian_stigler-0.0.3-py3-none-any.whl Python 3 none any Details for nbgrader_unittest_sebastian_stigler-0.0.3-py3-none-any.whl

Total release size: 7.5 kB

Release files / nbgrader_unittest_sebastian_stigler-0.0.3.tar.gz

Download URL nbgrader_unittest_sebastian_stigler-0.0.3.tar.gz
Size 3.3 kB
Tags Source
SHA-256 checksum
How to use checksums
a9c22d72c27389fd2181b068cf2ae7bbb995ab6151998fc369d3a6dd9bf1e228
BLAKE2b-256 checksum
How to use checksums
038430c16dde15bc3e55ddf28a24bfa4caf2c9b249d958c77585a6aa474a2fb4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.10

Release files / nbgrader_unittest_sebastian_stigler-0.0.3-py3-none-any.whl

Download URL nbgrader_unittest_sebastian_stigler-0.0.3-py3-none-any.whl
Size 4.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
527daf3fc962d3ecdd8506e100e201127ebcd5cf06874164a5086b4bd60c87a2
BLAKE2b-256 checksum
How to use checksums
5251ddc1f3dca62ba9a9105b0454c026dae0421cfcfe939b780ae29460c9eac4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.10

Security for nbgrader-unittest-sebastian-stigler 0.0.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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A 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.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.0.3 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page