hospital: healthchecks for Python

hospital makes it easy to setup and use health checks in Python.

Health checks are kind of tests applied to running applications and services.


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

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

You can reuse test libraries, like unittest:

import unittest
import hospital

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

    def test_http_200(self):
        """`hospital` online documentation returns HTTP 200."""
        url = ''
        hospital.assert_http_response(url, status_code=200)

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

Run health checks

Run health checks to make sure everything is ok. As an example, run health checks after a deployment to verify configuration, services...

Health checks are tests having a is_healthcheck attribute which is True. Let’s use this feature to capture and run the tests.

With nose (here we run health checks of hospital project):

nosetests --no-path-adjustment --all-modules --attr="is_healthcheck" hospital


You may want to skip health checks when you run unit/functional/integration tests. With nose, it could be:

nosetests --no-path-adjustment --all-modules --attr="!is_healthcheck" hospital

Plug in supervision, monitoring

Include health checks in supervision/monitoring tools.


In case of incidents, use health checks to diagnose problems.


Indices and tables

Read the Docs v: 0.2
On Read the Docs
Project Home

Free document hosting provided by Read the Docs.