https://github.com/vedro-universe/vedro-fn
Enables a functional-style syntax for defining Vedro scenarios
https://github.com/vedro-universe/vedro-fn
vedro vedro-plugin
Last synced: 3 months ago
JSON representation
Enables a functional-style syntax for defining Vedro scenarios
- Host: GitHub
- URL: https://github.com/vedro-universe/vedro-fn
- Owner: vedro-universe
- License: apache-2.0
- Created: 2025-01-19T09:25:39.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-06-15T18:16:57.000Z (12 months ago)
- Last Synced: 2026-02-15T07:19:21.478Z (4 months ago)
- Topics: vedro, vedro-plugin
- Language: Python
- Homepage:
- Size: 43.9 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# vedro-fn
[](https://codecov.io/gh/vedro-universe/vedro-fn)
[](https://pypi.python.org/pypi/vedro-fn/)
[](https://pypi.python.org/pypi/vedro-fn/)
[](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
Quick
For a quick installation, you can use a plugin manager as follows:
```shell
$ vedro plugin install vedro-fn
```
Manual
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
```
## 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"},
]
```