Simple test fixtures.
Project description
- Contact:
- z@etiol.net
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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file fix-1.0.3.tar.gz
.
File metadata
- Download URL: fix-1.0.3.tar.gz
- Upload date:
- Size: 18.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b378107a8975238fd27d1018bb4a78d86836f4f57769df86dadc127bc431001b |
|
MD5 | 07fd85c1c2f5b8164c530556e905e777 |
|
BLAKE2b-256 | 1ae4c9571c4c18d2db8557602e470e607bba0132570eeb6ae77f0d7965564ffb |
File details
Details for the file fix-1.0.3-py2.py3-none-any.whl
.
File metadata
- Download URL: fix-1.0.3-py2.py3-none-any.whl
- Upload date:
- Size: 5.6 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3ae4cde8797c7444a7385f69599849ca7b3dd3663fb35503281341cb22e82c7b |
|
MD5 | 08f7b7f543f6bdd02df768c36280f6e9 |
|
BLAKE2b-256 | 909b627043aa0968044debaaab41e529996bf4274da1086337d6fc4dd21f2abf |