Skip to main content

Pytest plugin to load fixtures from YAML files

Project description

pytest-fixture-maker: Load fixture data from local YAML files.


PyPI version PyPI

pytest-fixture-maker is a plugin for pytest, which load fixtures data from local YAML files.

Example file with fixtures:

# fixtures/test_fetch_by_key.yml


      - { key: 1, name: "Visa Classic" }
      - { key: 2, name: "Visa Gold"}

  - id: First test case
    account_key: 1
    expected: { key: 1, name: "Visa Classic" }
  - id: Second test case
    account_key: 2
    expected: { key: 2, name: "Visa Gold" }

  - id: Try fetch missing account
    account_key: 3
    expected_exc: AccountNotFound

Example file:


from typing import Any

import pytest

from tests.accounts import Account, AccountRepo, Storage

def account(request) -> Account:
    """Account entity."""
    return Account(**request.param)

def storage(request) -> Storage:
    """Entity storage."""
    storage = Storage()

    if "accounts" in request.param:
        accounts = [Account(**account) for account in request.param["accounts"]]
        storage.accounts = AccountRepo(accounts=accounts)

    return storage

def expected(request) -> Any:
    """Expected test case result."""
    return request.param

Example tests:

from typing import Type

import pytest

from tests.accounts import Account, AccountNotFound, Storage

def account_key(request) -> int:
    """Test account identifier."""
    return request.param

def expected(request) -> Account:
    """Expected test case result."""
    return Account(**request.param)

def test_success(storage: Storage, account_key: int, expected: Account) -> None:
    """Successful fetch account by key from storage."""
    result = storage.accounts.fetch_by_key(account_key)

    assert result == expected

def expected_exc(request) -> Type[AccountNotFound]:
    """Expected exception when account not found in storage."""
    return AccountNotFound

def test_missing(storage: Storage, account_key: int, expected_exc: Type[AccountNotFound]) -> None:
    """Try to fetch missing account by key from storage."""
    with pytest.raises(expected_exc):


To install pytest-fixture-maker, do:

(env) $ python3 -m pip install pytest-fixture-maker


0.1.0 (2021-09-19)

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

pytest-fixture-maker-0.2.0.tar.gz (4.6 kB view hashes)

Uploaded source

Built Distribution

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