Skip to main content

Numerous useful plugins for pytest.

Project description

Build Status codecov.io PyPI Status license

Copyright (C) 2016 Samuel Colvin

Numerous useful plugins for pytest.

Fixtures

tmpworkdir
Run the test with the working directory set to a temporary directory. Similar to the pytest plugin tmpdir except working directory is changed.
smart_caplog
capture logs with a smarter interface than pytest’s native caplog
print_logs
print all logs.
loop
asyncio loop.

Methods

(See below for usage examples).

mktree
Create a tree of files from a dictionary.
gettree
Return a dictionary depicting a directory tree.

Comparison Objects

All can be imported from pytest_toolbox.comparison.

CloseToNow
check that a date (or date-like object) is close to now
AnyInt
check tests that an object is an int
RegexStr
check that a string matches the regex
IsUUID
that that an object is an instance of UUID.

Used with equals as in my_date == CloseToNow(), these are useful when checking objects which contain a few unknown values are as expected

Eg.

assert {
    'details': {
        'user': 'foobar@example.com',
        'id': AnyInt(),
        'published': False,
        'event': 'an example',
        'created_ts': CloseToNow(),
    },
    'other_thing': [
        ...
    ],
    ...
} == obj

Usage

from pytest_toolbox import gettree, mktree

def test_whatever(tmpworkdir):
    mktree(tmpworkdir, {
        'foobar.txt': 'has this content'
    })
    assert gettree(tmpworkdir) = {'foobar.txt': 'has this content'}

TODO

Project details


Release history Release notifications

This version
History Node

0.4

History Node

0.2

History Node

0.1

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
pytest_toolbox-0.4-py35+-none-any.whl (6.2 kB) Copy SHA256 hash SHA256 Wheel py35+ Apr 7, 2018
pytest-toolbox-0.4.tar.gz (5.5 kB) Copy SHA256 hash SHA256 Source None Apr 7, 2018

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging CloudAMQP CloudAMQP RabbitMQ AWS AWS Cloud computing Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page