Skip to main content

A very simple check runner for Python. I use this in projects where I need to run a suite of checks before performing some action (usually on invocation). In this way, the checks are kept together in one class, and no special logic is needed to run them all individually.

Supports Python 2 and 3 (tested on 2.7 and 3.4).

Usage

Create a sub-class of CheckRunner and declare your checks:

from checkrunner import CheckRunner

class MyChecks(CheckRunner):
    @staticmethod
    def check_that_passes():
        return True, 'this check passed!'

    @staticmethod
    def check_that_fails():
        return False, 'this check failed!'

print(MyChecks.run())
# (False, ['this check failed!'])

print(MyChecks.run(return_passed=True))
# (False, ['this check passed!', 'this check failed!'])

When all checks pass it will return True with an empty list (unless you set return_passed):

from checkrunner import CheckRunner

class MyChecks(CheckRunner):
    @staticmethod
    def check_that_passes():
        return True, 'this check passed!'

print(MyChecks.run())
# (True, [])

You can pass keyword arguments to the checks (they will be sent to each and every check):

from checkrunner import CheckRunner

class MyChecks(CheckRunner):
    @staticmethod
    def check_foo(foo=None):
        if foo:
            return True, foo
        else:
            return False, foo

print(MyChecks.run(foo='bar', return_passed=True))
# (True, ['bar'])

Class methods also work:

from checkrunner import CheckRunner


class MyChecks(CheckRunner):
    foo = 'bar'

    @classmethod
    def check_class(cls):
        return True, cls.foo

print(MyChecks.run(return_passed=True))
# (True, ['bar'])

You can also return whatever you like in the second parameter, it does not have to be a string.

Testing

Testing uses vagrant, tox and pytest. If you already have Vagrant, running the tests yourself is as simple as:

$ vagrant up
$ vagrant ssh
(dev) vagrant@debian-8:~$ cd ~/src
(dev) vagrant@debian-8:~/src$ tox

Metadata

Release files for checkrunner 0.0.2

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

Source distribution (sdist)

Source distribution for checkrunner 0.0.2
File Size Uploaded
checkrunner-0.0.2.tar.gz 5.5 kB Details

Release files / checkrunner-0.0.2.tar.gz

Download URL checkrunner-0.0.2.tar.gz
Size 5.5 kB
Tags Source
SHA-256 checksum
How to use checksums
8880b3043423600414acc4c49c155d822f9f64a4561bc88f7fde067bb2406f33
BLAKE2b-256 checksum
How to use checksums
cca15c8a78ff2d558692463286dfbb73ee8592817a68f58dab3932d72f8c23ab
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.0.2 This release

1 release file

0.0.1

3 release files

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