Skip to main content

Handy fixtues to access your fixtures from your _pytest_ tests.

Project description

pytest fixtures fixtures

Fixtures, for fixtures. Handy fixtures to access your test fixtures from your pytest tests.

Installation

pip install pytest-fixtures-fixtures

Fixture Usage Guide

This plugin provides several fixtures to help you read and interact with test fixture files in your pytest tests.

Everything starts whith where you define your fixtures, by default, this plugin expects your fixtures to live in a folder named tests/fixtures from the root of your project. For example:

src
├── script.py
tests/
├── fixtures/
│   ├── users_data.txt
│   ├── app_config.json
│   └── error_logs.jsonl
└── test_script.py

If you wanted to read the users_data.txt file, you would use the read_fixture fixture:

def test_users_data(read_fixture):
    data = read_fixture("users_data.txt")
    assert "Alice" in data

If you wanted to read the app_config.json file, you would use the read_json_fixture fixture:

def test_app_config(read_json_fixture):
    config = read_json_fixture("app_config.json")
    assert config["database"]["host"] == "localhost"
    assert config["debug"] is True

There are more fixtures available to read different types of fixture files, including providing your own deserialization function. You can read the Fixtures Usage docs for more information.

Configure default fixtures directory

You can configure the default fixtures directory in several ways, the most common one is by redefining the fixtures_path fixture in your tests:

@pytest.fixture
def fixtures_path(tmp_path):
    """Use a temporary directory for fixtures."""
    path = tmp_path / "my_fixtures"
    path.mkdir()
    return path

You can read more about how to configure the default fixtures directory using configuration files or CLI in the Configuration docs.

Use fixtures to parametrize your tests

This plugin also provides a decorator to parametrize your tests using fixture files, for example:

id,a,b,c
add_positive,1,2,3
add_negative,1,-1,0
add_zero,5,0,5
@parametrize_from_fixture("data.csv")
def test_addition(a, b, c):
    assert int(a) + int(b) == int(c)

Will be expanded into three tests, each with different values for a, b, and c based on the data in the fixture file.

You can read more about how to use the parametrize_from_fixture decorator in the Parametrize docs.

A good example

pytest-fixtures-fixtures is tested using itself, you can see the tests in the tests directory.

Documentation

Why Use This Plugin?

  • Clean separation of test data and test logic
  • Multiple formats supported with consistent API
  • Automatic validation and clear error messages
  • Flexible configuration for different environments
  • Parametrization support with custom test IDs

Contributing

We welcome contributions! Please see our contributing guidelines and feel free to submit issues or pull requests.

License

This project is licensed under the MIT License - see the LICENSE file for details.

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

pytest_fixtures_fixtures-0.2.0.tar.gz (8.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pytest_fixtures_fixtures-0.2.0-py3-none-any.whl (9.8 kB view details)

Uploaded Python 3

File details

Details for the file pytest_fixtures_fixtures-0.2.0.tar.gz.

File metadata

File hashes

Hashes for pytest_fixtures_fixtures-0.2.0.tar.gz
Algorithm Hash digest
SHA256 801c78d44a8ee705a357df10f6b2addad8a730d263bbd26a70aa45a33a0a5ab7
MD5 d0ea709548384437f49e07ca281b559d
BLAKE2b-256 1de219dd0c090f31df2008a0815d9242870e767df64bb59643180ac884b48184

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytest_fixtures_fixtures-0.2.0.tar.gz:

Publisher: release.yml on fferegrino/pytest-fixtures-fixtures

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pytest_fixtures_fixtures-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for pytest_fixtures_fixtures-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5a0f7f7b080cade0c97fde93dfa3b33e73022cb7b24c1ec94fa85d3735b8141c
MD5 2c27f8ad463b3a9bf097a0f605f26c5f
BLAKE2b-256 21c344e129553205509efa70935a360bddf2a50acb97dded05d25a70c8d8a6ee

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytest_fixtures_fixtures-0.2.0-py3-none-any.whl:

Publisher: release.yml on fferegrino/pytest-fixtures-fixtures

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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