Skip to main content

Toffee: Test Object Factory Fixtures

Toffee creates factories for your model fixtures:

from toffee import Fixture, Factory

product_factory = Factory(Product, id=Seq())


class MyFixture(Fixture):
    product_1 = product_factory(desc='cuddly toy')
    product_2 = product_factory(desc='toy tractor')
    user = Factory(User, username='fred')
    order = Factory(Order, user=user, products=[product_1, product_2])


def test_product_search():
    with MyFixture() as f:
      assert f.product_1 in search_products('toy')
      assert f.product_2 in search_products('toy')

Toffee is similar in scope to factory_boy. The differences that prompted me to write a new library are:

  • Toffee promotes working with on fixtures as groups of objects to be created and destroyed as a unit, rather than individual factories

  • Explicit support for setup/teardown of fixtures

Read the Toffee documentation to find out more, or visit the bitbucket repo.

Toffee is developed and maintained by Olly Cope.

CHANGELOG

1.0.1 (released 2021-12-08)

  • Fixed compatibility issues with SQLALchemy v1.4+

1.0.0 (released 2019-05-15)

  • Added support for Python 3.7

  • Dropped support for Python 2.x

0.2.1 (released 2017-10-04)

  • Added support for Python 3.5, 3.6. Dropped support for Python 3.3, 3.4

Version 0.2.0

  • Dropped support for using setattr to configure subobjects. Use the double underscore convention instead.

  • Attribute/item setting on factory objects now results in the same operation being carried out on the generated object. This is useful for creating circular references between factory objects.

  • Lists of factory objects are now supported, making it easier to manage large numbers of test objects.

  • Factories now can take a partial flag. This stops the factory from producing a top-level named object, while still allowing it to be used for the basis of other factories.

Version 0.1.6

  • Added support for Python 3.4.

  • Dropped support for Python 3.2.

  • Tests that delete fixture objects before teardown is called no longer cause SQLAlchemy to invalidate the transaction (and thus potentially cause later tests to fail unexpectedly).

  • Added a scope argument to Seq(), that determines whether the sequence counter is reset at the start of each fixture set up or only once, at the start of the test run.

Version 0.1.5

  • Licensing: toffee is now licensed under the Apache License, Version 2.0

  • Bugfix: Fixed exception in LazyRecorderFactory.destroy_object during fixture teardown

Version 0.1.4

  • Added toffee.TestWithFixture

Version 0.1.3

  • The data mapper factories (SQLAlchemy and Storm) support querying for existing objects in fixtures

  • Added experimental SQLAlchemy support

Version 0.1.2

  • Made setting factoryoptions more flexible. It’s now possible to change the default flush/commit behavior of StormFactory per fixture class and or at setup time when using the context manager syntax.

Version 0.1.1

  • Bugfix: StormFactory did not flush/commit the store on fixture teardown teardown, meaning the store would not be left clean for subsequent operations

Version 0.1

  • initial release

Release files for toffee 1.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for toffee 1.0.1
File Size Uploaded
toffee-1.0.1.tar.gz 13.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for toffee 1.0.1
File Interpreter ABI Platform
toffee-1.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 27.8 kB

Release files / toffee-1.0.1.tar.gz

Download URL toffee-1.0.1.tar.gz
Size 13.7 kB
Tags Source
SHA-256 checksum
How to use checksums
1af7c726effe1f3dafd63fefd4f2a854b138c7bb2fde31c5f5cbb31f6224bff8
BLAKE2b-256 checksum
How to use checksums
1ed703cc293d8507c32f29abeb18f43fca92c158b006467a15524d9211f8dc5c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.7.0 requests/2.22.0 setuptools/57.0.0 requests-toolbelt/0.9.1 tqdm/4.58.0 CPython/3.7.12

Release files / toffee-1.0.1-py3-none-any.whl

Download URL toffee-1.0.1-py3-none-any.whl
Size 14.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4fac0ede28a7c4836476e0b2abefecbcd08326ae5cbbf20cca7e474b58138749
BLAKE2b-256 checksum
How to use checksums
85ad914d206a919b17ea8be76831e7e0a2bb3790dcf65944fc2eb5c2609b3b0e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.7.0 requests/2.22.0 setuptools/57.0.0 requests-toolbelt/0.9.1 tqdm/4.58.0 CPython/3.7.12

Release history Release notifications | RSS feed

This release

1.0.1 This release

2 release files

1.0.0

2 release files

0.2.1

2 release files

0.2.0

1 release file

0.1.6

1 release file

0.1.5

1 release file

0.1.4

1 release file

0.1.3

1 release file

0.1.2

1 release file

0.1.1

1 release file

0.1

1 release file

0

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page