This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (pypi.python.org).
Help us improve Python packaging - Donate today!

Simple test fixtures.

Project Description

fix is a simple library to assist with the creation of fixtures for test functions, methods etc. It provides one decorator, with_fixture, which allows you to attach setup() and teardown() functions to the decorated callable, and access information defined in the fixture from within the test function.

fix was written for use with nose, but doesn’t depend on it, and may also prove useful with other test frameworks.

Examples

Here’s a basic example with setup but no teardown:

from fix import with_fixture

def setup_only(context):

    def setup():
        """Add something to the context."""
        assert context == {}
        context.squee = "kapow"

    return setup

@with_fixture(setup_only)
def case(context):
    assert context == {"squee": "kapow"}

… and here’s a rather more involved one that creates some temporary files to work with, then deletes them during teardown:

import os
import shutil
import tempfile

from fix import with_fixture

def external(context, files=3):

    def setup():
        context.temp_dir = tempfile.mkdtemp()
        context.filenames = ["file_%03d" % i for i in range(files)]
        for filename in context.filenames:
            with open(os.path.join(context.temp_dir, filename), "w") as f:
                f.write("This is the file %r.\n" % filename)

    def teardown():
        shutil.rmtree(context.temp_dir)

    return setup, teardown

@with_fixture(external, files=5)
def check_files(context):
    present = 0
    absent = 0
    for filename in context.filenames:
        if os.path.exists(os.path.join(context.temp_dir, filename)):
            present += 1
        else:
            absent += 1
    return context.temp_dir, present, absent

temp_dir, present, absent = check_files()
assert not os.path.exists(temp_dir)
assert present == 5
assert absent == 0

Installation

This should do the trick:

pip install fix

Licence

fix is released under the GNU General Public License (version 3 or later), a copy of which is included with this distribution in the file COPYING.

Release History

Release History

This version
History Node

1.0.3

History Node

1.0.2

History Node

1.0.1

History Node

1.0.0

History Node

1.0.0a1

History Node

0.12.08a3

History Node

0.12.08a2

History Node

0.12.08a1

Download Files

Download Files

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

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
fix-1.0.3-py2.py3-none-any.whl (5.6 kB) Copy SHA256 Checksum SHA256 py2.py3 Wheel Apr 11, 2017
fix-1.0.3.tar.gz (18.7 kB) Copy SHA256 Checksum SHA256 Source Apr 11, 2017

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting