pytest-fixture-maker: Load fixture data from local YAML files.
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
---
test_fetch_by_key:
storage:
accounts:
- { key: 1, name: "Visa Classic" }
- { key: 2, name: "Visa Gold"}
test_success:
- 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" }
test_missing:
- id: Try fetch missing account
account_key: 3
expected_exc: AccountNotFound
Example conftest.py file:
# conftest.py
from typing import Any
import pytest
from tests.accounts import Account, AccountRepo, Storage
@pytest.fixture(scope="function")
def account(request) -> Account:
"""Account entity."""
return Account(**request.param)
@pytest.fixture(scope="function")
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
@pytest.fixture(scope="function")
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
@pytest.fixture
def account_key(request) -> int:
"""Test account identifier."""
return request.param
@pytest.fixture
def expected(request) -> Account:
"""Expected test case result."""
return Account(**request.param)
@pytest.mark.integration
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
@pytest.fixture
def expected_exc(request) -> Type[AccountNotFound]:
"""Expected exception when account not found in storage."""
return AccountNotFound
@pytest.mark.integration
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):
storage.accounts.fetch_by_key(account_key)
Installation
To install pytest-fixture-maker, do:
(env) $ python3 -m pip install pytest-fixture-maker
Changelog
0.1.0 (2021-09-19)
Initial release.
Metadata
Release files for pytest-fixture-maker 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pytest-fixture-maker-0.2.0.tar.gz | 4.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pytest_fixture_maker-0.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 9.1 kB
Release files / pytest-fixture-maker-0.2.0.tar.gz
| Download URL | pytest-fixture-maker-0.2.0.tar.gz |
|---|---|
| Size | 4.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1085411c1d7715cd485546ffdc6e316f8d59816e790c1b10267073f10bf1a180
|
|
BLAKE2b-256 checksum How to use checksums |
df5c643f9e10dc5568ac16d50a799ab08d16647a3e3ac1c9c99c9705c1ba806e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.9 CPython/3.8.10 Linux/5.8.0-1041-azure
|
Release files / pytest_fixture_maker-0.2.0-py3-none-any.whl
| Download URL | pytest_fixture_maker-0.2.0-py3-none-any.whl |
|---|---|
| Size | 4.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
87fcad31a13d1e26bae789b91e449f4612ea1c73c395d40dc8e8b5ed735f8ed8
|
|
BLAKE2b-256 checksum How to use checksums |
6f261d7033b3ac7d3705e5f1642253d242c27a34eebd5b51b663395cbc74efe3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.9 CPython/3.8.10 Linux/5.8.0-1041-azure
|