Skip to main content

Enables a functional-style syntax for defining Vedro scenarios

Project description

vedro-fn

Codecov PyPI PyPI - Downloads Python Version

A plugin for the Vedro framework that enables a functional-style syntax for defining Vedro scenarios.

(!) Starting with Vedro v1.14, the functional‑style scenario syntax is available directly in Vedro core. Use vedro-fn only if your project is on Vedro v1.13 or earlier, or if you need backward‑compatibility with older versions.

Installation

Quick

For a quick installation, you can use a plugin manager as follows:

$ vedro plugin install vedro-fn

Manual

To install manually, follow these steps:

  1. Install the package using pip:
$ pip3 install vedro-fn
  1. Next, activate the plugin in your vedro.cfg.py configuration file:
# ./vedro.cfg.py
import vedro
import vedro_fn


class Config(vedro.Config):
    class Plugins(vedro.Config.Plugins):
        class VedroFn(vedro_fn.VedroFn):
            enabled = True

Usage

Basic Example

import base64
from vedro_fn import scenario, given, when, then

@scenario()
def decode_base64_encoded_str():
    with given:
        encoded = "YmFuYW5h"

    with when:
        decoded = base64.b64decode(encoded)

    with then:
        assert decoded == b"banana"

To run scenarios, use:

$ vedro run

Using Scenario Decorators

Scenario decorators (such as @skip, @only, etc.) can be passed via an extended syntax:

import base64
from vedro import skip
from vedro_fn import scenario, given, when, then

@scenario[skip]()
def decode_base64_encoded_str():
    with given:
        encoded = "YmFuYW5h"

    with when:
        decoded = base64.b64decode(encoded)

    with then:
        assert decoded == b"banana"

Parametrization

You can also use Vedro’s built-in @params decorator with @scenario for parametrized scenarios:

import base64
from vedro import params
from vedro_fn import scenario, when, then

@scenario([
    params("YmFuYW5h", b"banana"),
    params("", b""),
])
def decode_base64_encoded_str(encoded, expected):
    with when:
        decoded = base64.b64decode(encoded)

    with then:
        assert decoded == expected

Async Example

Here’s an example of an asynchronous scenario:

from vedro_fn import scenario, when, then
from interfaces.api import fetch_users

@scenario()
async def fetch_users_from_api():
    with when:
        users = await fetch_users()

    with then:
        assert users == [
            {"id": 1, "name": "Bob"},
            {"id": 2, "name": "Alice"},
        ]

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

vedro_fn-0.1.2.tar.gz (12.0 kB view details)

Uploaded Source

Built Distribution

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

vedro_fn-0.1.2-py3-none-any.whl (10.6 kB view details)

Uploaded Python 3

File details

Details for the file vedro_fn-0.1.2.tar.gz.

File metadata

  • Download URL: vedro_fn-0.1.2.tar.gz
  • Upload date:
  • Size: 12.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.10

File hashes

Hashes for vedro_fn-0.1.2.tar.gz
Algorithm Hash digest
SHA256 bcfe2ca88c6082ed8572ff2c06c574945351511e3a20d8abc2ddad070f9cded2
MD5 25dc85451079177c3d1eb64ce1b30da7
BLAKE2b-256 e0dc29ac3cd3c1a92b25629643ca066dd103de07e9d442c3ea47babdd8a36fe0

See more details on using hashes here.

File details

Details for the file vedro_fn-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: vedro_fn-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 10.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.10

File hashes

Hashes for vedro_fn-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 eec5a5da769b04b60f100d7ba562f0feed39b947950c8cd81a8fd5bee0cd2553
MD5 0877d88aeb5f19987770d7aebdcfb09e
BLAKE2b-256 3d2bd89f0e1f7fcde9de590049d5bc9a5c3c02a2544552650409d49fa6672650

See more details on using hashes here.

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