Skip to main content

Facture

Overview

Facture is FAC-tories that generate partition-isolated fix-TURE data, ideal for elaborating scenarios.

Installation

pip install facturedata

How is this different from factories and fixtures?

Originally this tool was created to generate the test data for a database that had very high overhead per-insert. Using traditional data factories and individual transactions with rollback would not work; batching the inserts was necessary.

Fixtures alone could solve this problem, but it’s really hard to enumerate and manage the joins in a large number of scenarios in fixtures effectively. The primary advantage that factories have is their ease of use in testing individual scenarios without needing to understand other scenarios or manage a corpus of shared data. Carefully paritioning inserted data so the data is unambiguously owned by a scenario can provide the same benefit as factories, where it becomes easy to understand the data associated with individual scenarios.

How to Use

There is a fair amount of configuration that goes into setting facture up, but here is a quick inline example data group that shows how foreign keys work:

'group': 'facture_group_shawshank_redemption',
'offset': 100,
'data': [
    ['actors a_mf', {'attrs': {'first_name': 'Morgan', 'last_name': 'Freeman'}}],
    ['actors a_tr', {'attrs': {'first_name': 'Tim', 'last_name': 'Robbins'}}],
    ['films f', {'attrs': {'name': 'Shawshank Redemption', 'year': '1994'}}],
    ['roles r1', {'refs': {'actor_id': '.a_mf.id', 'film_id': '.f.id'}}],
    ['roles r1', {'refs': {'actor_id': '.a_tr.id', 'film_id': '.f.id'}}]
]

For a deeper dive I recommend that you look at this example: https://github.com/gmccreight/facture/tree/master/tests/examples/sql_inject_target

Copy the factureconf.py there to the directory you will be running facture in. Look at the facture_json target section in the original.sql file and copy it into a file of your own choosing. Update the conf_targets section of your newly created factureconf.py file to point to the file where you put the facture_json.

Run:

facture

Your target file should now be filled in with some generated data. You’re off to the races!

Additional benefits

  • “compile”-time factory configuration consistency checks. Checks for many typos, join issues, etc.

  • Materializes the output into your version-controlled files, unrolling the complexity. Because the fixtures that we generate are automatically created, we can put a lot of effort into making the generated data comprehensible (and lineage-providing). This means we annotate all generated data with the column names, and the scenario name. It’s also extremely easy to see what the effects of any change you make is, since it’s all laid out for you.

  • Code as configuration. The configuration files are written in Python, so you have the full power of the language.

  • Easy to reason about each scenario in complete isolation because of data partitioning

  • Plays well with others… can be introduced into existing fixtures. Integrates with how you do things, doesn’t try to take over completely. Can target files or sections within files.

Metadata

Release files for facturedata 0.2.02

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

Source distribution (sdist)

Source distribution for facturedata 0.2.02
File Size Uploaded Provenance Actions
facturedata-0.2.02.tar.gz 9.2 kB Without provenance Details for facturedata-0.2.02.tar.gz

Release files / facturedata-0.2.02.tar.gz

Download URL facturedata-0.2.02.tar.gz
Size 9.2 kB
Tags Source
SHA-256 checksum
How to use checksums
b11c2e6856d597bf83003606de17542b43a36b51909b912bfd728f6fef304840
BLAKE2b-256 checksum
How to use checksums
1bb638723eba2c01984364daa07d835b4a489db01033a2c6a22d14f574b70e38
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.40.2 CPython/3.8.0

Security for facturedata 0.2.02

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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