Skip to main content

yieldfixture

https://travis-ci.org/podhmo/yieldfixture.svg?branch=master

how to use

from yieldfixture import create
run, yield_fixture = create()


@yield_fixture
def f():
    print(">>> f")
    yield 1
    print(">>> f")


@yield_fixture
def g():
    print("  >>> g")
    yield 2
    print("  >>> g")


@run
def use_it(x, y):
    print("{} + {} = {}".format(x, y, x + y))

output

>>> f
  >>> g
1 + 2 = 3
  >>> g
>>> f

with context

from yieldfixture import create, with_context
run, yield_fixture = create()


@yield_fixture
@with_context
def f(ctx):
    i = ctx["i"] = 0
    print("{}>>> f".format("  " * i))
    yield 1
    print("{}>>> f".format("  " * i))


@yield_fixture
@with_context
def g(ctx):
    i = ctx["i"] = ctx["i"] + 1
    print("{}>>> g".format("  " * i))
    yield 2
    print("{}>>> g".format("  " * i))


@run
def use_it(x, y, *, i=0):
    print("{}{} + {} = {}".format("  " * (i + 1), x, y, x + y))

output

>>> f
  >>> g
    1 + 2 = 3
  >>> g
>>> f

when a exception is raised

from yieldfixture import create, with_context
run, yield_fixture = create()


@yield_fixture
@with_context
def f(ctx):
    i = ctx["i"] = 0
    print("{}>>> f".format("  " * i))
    yield 1
    print("{}>>> f".format("  " * i))


@yield_fixture
@with_context
def g(ctx):
    i = ctx["i"] = ctx["i"] + 1
    print("{}>>> g".format("  " * i))
    yield 2
    print("{}>>> g".format("  " * i))


@run
def use_it(x, y, *, i=0):
    print("{}{} + {} = {}".format("  " * (i + 1), x, y, x + y))
    1 / 0

output

>>> f
  >>> g
    1 + 2 = 3
  >>> g
>>> f
Traceback (most recent call last):
  File "examples/02withexception.py", line 24, in <module>
    def use_it(x, y, *, i=0):
  File "$HOME/vboxshare/venvs/my3/yieldfixture/yieldfixture/__init__.py", line 125, in run_with
    return fn(*ctx.args, **ctx.kwargs)
  File "examples/02withexception.py", line 26, in use_it
    1 / 0
ZeroDivisionError: division by zero

selective fixture activation

from yieldfixture import create, with_context
run, yield_fixture = create()


@yield_fixture
@with_context
def f(ctx):
    i = ctx["i"] = ctx.get("i", -1) + 1
    print("{}>>> f".format("  " * i))
    yield 1
    print("{}>>> f".format("  " * i))


@yield_fixture
@with_context
def g(ctx):
    i = ctx["i"] = ctx.get("i", -1) + 1
    print("{}>>> g".format("  " * i))
    yield 2
    print("{}>>> g".format("  " * i))


@run
def use_it(x, y, *, i=0):
    print("{}{} + {} = {}".format("  " * (i + 1), x, y, x + y))


@run([g, f])
def use_it2(x, y, *, i=0):
    print("{}{} + {} = {}".format("  " * (i + 1), x, y, x + y))

output

>>> f
  >>> g
    1 + 2 = 3
  >>> g
>>> f
>>> g
  >>> f
    2 + 1 = 3
  >>> f
>>> g

0.3.2

  • only tuple treated as multiple values

0.3.1

  • dispatch hook

0.3.0

  • some internal refactoring(mainly, rename methods)

0.2.0

  • calling teardown action, absolutely

0.1.1

  • first release

Metadata

Release files for yieldfixture 0.3.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for yieldfixture 0.3.2
File Size Uploaded Provenance Actions
yieldfixture-0.3.2.tar.gz 3.4 kB Without provenance Details for yieldfixture-0.3.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for yieldfixture 0.3.2
File Interpreter ABI Platform Actions
yieldfixture-0.3.2-py2.py3-none-any.whl Python 2, Python 3 none any Details for yieldfixture-0.3.2-py2.py3-none-any.whl

Total release size: 8.4 kB

Release files / yieldfixture-0.3.2.tar.gz

Download URL yieldfixture-0.3.2.tar.gz
Size 3.4 kB
Tags Source
SHA-256 checksum
How to use checksums
8ddabe36c1f93c26a25d438efa2b26644446358bad3c00adf215c3a14d355dd9
BLAKE2b-256 checksum
How to use checksums
2fe5118f3f164ba2ba38aa01aea7566feb2e712919dd39dc5df91d4e73531099
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / yieldfixture-0.3.2-py2.py3-none-any.whl

Download URL yieldfixture-0.3.2-py2.py3-none-any.whl
Size 4.9 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
38e7e669c7e3cb95e391e7910119979de58db9d3a29675d13556ce563f0eb693
BLAKE2b-256 checksum
How to use checksums
e9bb8f0b70c5ee8e2cd4db5c882825bed0cd20a5ff4a7fa94fe0cdd432101d3a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for yieldfixture 0.3.2

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