Skip to main content

Whitesmith

Test helper for blacksmith resources.

Continuous Integration Coverage

Motivation

Whitesmith is the swissknife for developping and testing code base that use [[https://](https://github.com/mardiros/blacksmith](blacksmith).

While using blacksmith, resources are declared using pydantic, and, while testing, we never do http calls.

Whitesmith is a helper that create pytest fixtures with handlers for tests, client types and generate documentation for blacksmith resources and .

Usage

Generating typed client

The command bellow will create a file blacksmith_client.py in the codebase that override the blacksmith client factory to get a fully typed client.

whitesmith generate-types -m my_package.resources -o my_package/resources/blacksmith_client.py

Use --overwrite if the file exists and you want to regenerate it.

Now, you can import the AsyncAppClientFactory or SyncAppClientFactory to get a fully typed client and not import blacksmith module anywhere from the codebase.

Generating fixtures

The command below will generate a folder tests/whitesmith containing handlers for all the api call with a default implementation.

whitesmith generate-handlers -m my_package.resources --out-dir tests/

Note If you run the command again, the command does not overwrite generated files. To generate a newer version, use the --overwrite flag.

Those fixtures can be adapted to get the result you want, they must be present in a whitesmith_handlers directory inside the tests suite.

Using the fixtures

The whitesmith package provide three pytest fixtures that can be used in the testsuite.

The fixtures sync_blacksmith_client, async_blacksmith_client can be used to get a blacksmith client instance that use the installed fixtures from the generated directory.

Both actually consume the undelying fixtures whitesmith_router is a generated fixture that contains all the routes contained inside a whitesmith_handlers directory. This directory is the one created by the commande above whitesmith generate-handlers.

You can have multiple whitesmith_handlers by creating tests submodules to handle mulptiple behavior when its needed.

Building a client contract (open api format)

This feature is a bit experimental but was the main motivation of blacksmith, provide a tool for consumer-driven contract (CDC) so generated document of client contract is nice to have. A tool to ensure server and client contract compatibility could be used to enforce maintainability.

uv run whitesmith generate-openapi -m my_package.resources -o docs/resources/openapis --overwrite
cd docs/resources/openapis
python -m http.server 8000

Metadata

Release files for whitesmith 6.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 whitesmith 6.0.1
File Size Uploaded Provenance Actions
whitesmith-6.0.1.tar.gz 15.3 kB Without provenance Details for whitesmith-6.0.1.tar.gz

Built distribution (wheel)

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

Total release size: 34.2 kB

Release files / whitesmith-6.0.1.tar.gz

Download URL whitesmith-6.0.1.tar.gz
Size 15.3 kB
Tags Source
SHA-256 checksum
How to use checksums
2f3818310b38929aa2a71b402649ab7a3f8da6661a3a5eca52d93c51a95ece1d
BLAKE2b-256 checksum
How to use checksums
8d55aec21d4adbcb45962494bc95b5421aeaa103ca0733809100c1dfd9f56e49
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via pdm/2.29.7 CPython/3.13.18 Linux/7.0.0-1020-azure

Release files / whitesmith-6.0.1-py3-none-any.whl

Download URL whitesmith-6.0.1-py3-none-any.whl
Size 18.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
560c3683bdba6ee873b4c96197f8ff7d6175a1d6d83c469bbcc1b4eb0ad86960
BLAKE2b-256 checksum
How to use checksums
02eb8e24deab2950d18ec7ebaadbe80b95bb4ce1a875160f088b7c5788f61e3c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via pdm/2.29.7 CPython/3.13.18 Linux/7.0.0-1020-azure

Security for whitesmith 6.0.1

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