python-hospital / hospital

Tools to diagnose Python projects (supervision, monitoring).
Other
40 stars 8 forks source link

Context manager and utilities to collect/combine results of multiple assertions #34

Open benoitbryon opened 10 years ago

benoitbryon commented 10 years ago

In order to replace things like:

@hospital.healthcheck
def test_multiple():
    errors = []
    for domain in 'example.com', 'www.example.com':
        try:
            hospital.assert_ping(domain)
        except AssertionError, e:
            errors.append(e)
    if errors:
        raise AssertionError('\n'.join(errors))

With something like:

@hospital.healthcheck
def test_multiple():
    with hospital.multiple_assertions:
        for domain in 'example.com', 'www.example.com':
            hospital.assert_ping(domain)
benoitbryon commented 10 years ago

Ideas: