Write health checks

Write health checks just like you would write tests. The main difference is their scope: they check “production” facts instead of mocks/fakes/dummies.

Health checks are special kind of tests. Use healthcheck() decorator to differenciate health checks from tests.

Just like tests, health checks can be simple functions that perform assertions:

import sys
import hospital

@hospital.healthcheck
def test_python_version():
    """Python version >= 2."""
    assert sys.version_info[0] >= 2

You can reuse test libraries, like unittest:

import unittest
import hospital

@hospital.healthcheck
class DocumentationHealthCheck(unittest.TestCase):
    """Check `hospital` online documentation."""
    def test_ping(self):
        """`hospital` documentation server responds to ping."""
        hostname = 'hospital.readthedocs.org'
        hospital.assert_ping(hostname)

    def test_http_200(self):
        """`hospital` online documentation returns HTTP 200."""
        url = 'http://hospital.readthedocs.org/en/0.1/'
        hospital.assert_http_response(url, status_code=200)

Hospital provides a set of useful assertions and health check suites.