Metadata-Version: 2.4
Name: vedro-fn
Version: 0.1.2
Summary: Enables a functional-style syntax for defining Vedro scenarios
Home-page: https://github.com/vedro-universe/vedro-fn
Author: Nikita Tsvetkov
Author-email: tsv1@fastmail.com
License: Apache-2.0
Project-URL: Docs, https://github.com/vedro-universe/vedro-fn
Project-URL: GitHub, https://github.com/vedro-universe/vedro-fn
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Typing :: Typed
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: vedro<2.0,>=1.12
Dynamic: author
Dynamic: author-email
Dynamic: classifier
Dynamic: description
Dynamic: description-content-type
Dynamic: home-page
Dynamic: license
Dynamic: license-file
Dynamic: project-url
Dynamic: requires-dist
Dynamic: requires-python
Dynamic: summary

# vedro-fn

[![Codecov](https://img.shields.io/codecov/c/github/vedro-universe/vedro-fn/main.svg?style=flat-square)](https://codecov.io/gh/vedro-universe/vedro-fn)
[![PyPI](https://img.shields.io/pypi/v/vedro-fn.svg?style=flat-square)](https://pypi.python.org/pypi/vedro-fn/)
[![PyPI - Downloads](https://img.shields.io/pypi/dm/vedro-fn?style=flat-square)](https://pypi.python.org/pypi/vedro-fn/)
[![Python Version](https://img.shields.io/pypi/pyversions/vedro-fn.svg?style=flat-square)](https://pypi.python.org/pypi/vedro-fn/)

A plugin for the [Vedro](https://vedro.io) framework that enables a functional-style syntax for defining Vedro scenarios.

(!) Starting with [Vedro v1.14](https://vedro.io/blog/whats-new-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

<details open>
<summary>Quick</summary>
<p>

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

```shell
$ vedro plugin install vedro-fn
```

</p>
</details>

<details>
<summary>Manual</summary>
<p>

To install manually, follow these steps:

1. Install the package using pip:

```shell
$ pip3 install vedro-fn
```

2. Next, activate the plugin in your `vedro.cfg.py` configuration file:

```python
# ./vedro.cfg.py
import vedro
import vedro_fn


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

</p>
</details>

## Usage

### Basic Example

```python
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:

```shell
$ vedro run
```

### Using Scenario Decorators

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

```python
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:

```python
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:

```python
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"},
        ]
```
