Enables a functional-style syntax for defining Vedro scenarios
Project description
vedro-fn
A plugin for the Vedro framework that enables a functional-style syntax for defining Vedro scenarios.
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:
- Install the package using pip:
$ pip3 install vedro-fn
- Next, activate the plugin in your
vedro.cfg.pyconfiguration 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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file vedro_fn-0.1.1.tar.gz.
File metadata
- Download URL: vedro_fn-0.1.1.tar.gz
- Upload date:
- Size: 11.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
add726794ccf0c808ca4ef521c31bc682d88d4e8f7973bec6d1617c4c4de6b66
|
|
| MD5 |
853dda5319e7524fe6790a938ef304a6
|
|
| BLAKE2b-256 |
183c6a242f0cfb4040057df327f18ab215bb74c6dbea51501d3f2db898b0ff9f
|
File details
Details for the file vedro_fn-0.1.1-py3-none-any.whl.
File metadata
- Download URL: vedro_fn-0.1.1-py3-none-any.whl
- Upload date:
- Size: 10.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
08ee07c556d85dd13620c1050c7d18d1364105ed2ad9fab5d35e7bd803df33fb
|
|
| MD5 |
5f0707dcbe925151913da84b37fa16be
|
|
| BLAKE2b-256 |
58813c25afa69c345c54ad9b0bf2a5396a597f17634627293536db58da8aa161
|