
Pytest-voluptuous – a pytest plugin for asserting data against python schema - tuukkamustonen
https://github.com/F-Secure/pytest-voluptuous
======
tuukkamustonen
So in short, rather than doing something like:

    
    
        assert 'info' in r
        assert 'package_url' in r['info']
        assert len(r['info']['package_url']) >= 10
    

This plugin allows you to rather:

    
    
        assert S({
            'info': {
                'package_url': Length(min=10)
            }
        }) == r
    

It bolts on into pytest and provides a sensible error message in case
validation fails. See README at [https://github.com/F-Secure/pytest-
voluptuous](https://github.com/F-Secure/pytest-voluptuous) for docs.

Background: There's not much code in it, but this is what I've been using to
validate the responses of my flask application for a while now (as commit
history will tell). It's simple and useful, as you can focus on just the
interesting bits, and abstract away the nitty gritty details that might step
into way. It also allows to keep the syntax concise, and reduces amount of
boilerplate you'd have to write otherwise.

