Skip to main content

a testfixture helper

Project description

mete0r.testfixture

a testfixture helper

Quickstart

To install:

pip install mete0r.testfixture

Let’s assume your project has following structure:

yourproject/
    setup.py
    yourpackage/
        __init__.py
        tests/
            __init__.py
            test_foo.py
            fixtures/
                foo.py
                bar.py

Define a fixture in yourpackage/tests/fixtures/foo.py:

from mete0r_testfixture.testfixture import testfixture

@testfixture('Foo')
def foo(fixtures):
    return {
        'foo': None,
    }

Define another fixture in yourpackage/tests/fixtures/bar.py:

@testfixture('Bar', 'foo')
def bar(fixtures):
    return {
        'bar': fixtures.get('Foo')
    }

Now you can use them in your tests:

# yourpackage/tests/test_foo.py
from unittest import TestCase
from mete0r_testfixture.testfixture import TestFixtures
from . import fixtures

class FooTest(TestCase):

    def test_foo(self):
        testfixtures = TestFixtures('yourpackage.tests.fixtures')
        self.assertEquals({
            'bar': {
                'foo': None,
            },
        }, testfixtures.get('Bar', 'foo')

You can also list test fixtures defined in your packages:

$ mete0r-testfixture-scan yourpackage
Foo          yourpackage.tests.fixtures.foo.foo
Bar, foo     yourpackage.tests.fixtures.bar.bar

Caveat

mete0r.testfixture uses venusian to scan fixtures, so be careful not to scan test fixtures in your main application/package. For example:

config = Configurator(...)  # pyramid configurator
...
config.scan(ignore=[b'yourpackage.tests'])

Development environment

To setup development environment:

python setup.py virtualenv
make

Changes

0.0.2 (2017-04-08)

  • Scans modules in the added order.

0.0.1 (2017-04-08)

  • Changes usage.

0.0.0 (2017-01-27)

  • Initial release.

Project details


Download files

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

Source Distribution

mete0r.testfixture-0.0.2.tar.gz (77.8 kB view details)

Uploaded Source

File details

Details for the file mete0r.testfixture-0.0.2.tar.gz.

File metadata

File hashes

Hashes for mete0r.testfixture-0.0.2.tar.gz
Algorithm Hash digest
SHA256 2601fd4f7d26e1584752dee738c553da723ec018de32f873a3aa53e59605984b
MD5 3245152c4b44b0f5f02650d7165f01b6
BLAKE2b-256 3d1ec51c7a42b0a187af22d6144ccf0ddf5bdef6037403cdf81528d83441b110

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page