pytest-class-fixtures — Object-oriented fixtures for pytest
Turn your class into a fixture
Ever have PyTest ´s @fixture tell you this?
ValueError: class fixtures not supported (maybe in the future)
well, the future is now:
from pytest_class_fixtures import class_fixture
@class_fixture(name="calc")
class Calculator:
def __init__(self):
self.result = 0
def test_calculator_initial_state(calc):
assert calc.result == 0
Do you want BDD with that?
# calculator.feature
Feature: Calculator
Scenario: Addition
Given the calculator is cleared
When I add 5
Then the result should be 5
import pytest
from pytest_bdd import given, when, then, parsers, scenarios
from pytest_class_fixtures import class_fixture
scenarios("calculator.feature")
@class_fixture(name="calc")
class Calculator:
def __init__ (self):
self.clear()
@given("the calculator is cleared")
def clear (self):
self.result = 0
@when(parsers.parse("I add {number}"))
def add (self, number):
self.result += int(number)
@then(parsers.parse("the result should be {result}"))
def check_result(calc, result):
assert calc.result == int(result)
Metadata
Release files for pytest-class-fixtures 0.1.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 | Provenance | |
|---|---|---|---|---|
| pytest_class_fixtures-0.1.0.tar.gz | 2.2 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pytest_class_fixtures-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 4.9 kB
Release files / pytest_class_fixtures-0.1.0.tar.gz
| Download URL | pytest_class_fixtures-0.1.0.tar.gz |
|---|---|
| Size | 2.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f1420666e43a395918e213b3641bff4d03f90feeff2be1c0db40b06e94c773f5
|
|
BLAKE2b-256 checksum How to use checksums |
bab6a8edfcc9f7245eea3c3aa2ca16996deabf5ca5103ceda6ebb760283d11cf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.4 CPython/3.13.0 Darwin/23.6.0
|
Release files / pytest_class_fixtures-0.1.0-py3-none-any.whl
| Download URL | pytest_class_fixtures-0.1.0-py3-none-any.whl |
|---|---|
| Size | 2.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1cf97b949f75ef497c90a25536dae513618fad259b152a3b9af3f106bebf1508
|
|
BLAKE2b-256 checksum How to use checksums |
4d283682d323bacb462015d5494c3baf0d221e64a73968ed5fbff203c7286b81
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.4 CPython/3.13.0 Darwin/23.6.0
|
Security for pytest-class-fixtures 0.1.0
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.