vedro
The vedro-valera-validator package allows you to use d42 as a validation tool for your Vedro tests.
Installation
1. Install package
To install the package, use the following command:
$ pip3 install vedro-valera-validator
2. Enable plugin
To enable the plugin, create a vedro.cfg.py
file in the root of your project and add the following code:
# ./vedro.cfg.py
import vedro
import vedro_valera_validator as valera_validator
class Config(vedro.Config):
class Plugins(vedro.Config.Plugins):
class ValeraValidator(valera_validator.ValeraValidator):
enabled = True
Usage
To use the vedro-valera-validator
package, create a scenario file in the ./scenarios
directory of your project. In this scenario file, you can define the test scenario and its steps, as shown in the example below:
# ./scenarios/decode_base64_encoded_string.py
import vedro
from base64 import b64decode
from d42 import schema
class Scenario(vedro.Scenario):
subject = "decode base64 encoded string"
def given(self):
self.encoded = "Y3VjdW1iZXI="
def when(self):
self.result = {
"result": b64decode(self.encoded)
}
def then(self):
assert self.result == schema.dict({
"result": schema.bytes(b"banana")
})
Run tests
To run the tests, use the following command:
$ vedro run
This will run the tests and output the results. If the tests fail, a ValidationException will be raised, indicating which validation rule was not met. For example:
Scenarios
*
✗ decode base64 encoded string
✔ given
✔ when
✗ then
╭────────────────────── Traceback (most recent call last) ─────────────────────╮
│ ./scenarios/decode_base64_encoded_string.py:19 in then │
│ │
│ 16 │ │ } │
│ 17 │ │
│ 18 │ def then(self): │
│ ❱ 19 │ │ assert self.result == schema.dict({ │
│ 20 │ │ │ "result": schema.bytes(b"banana") │
│ 21 │ │ }) │
│ 22 │
╰──────────────────────────────────────────────────────────────────────────────╯
ValidationException:
- Value <class 'bytes'> at _['result'] must be equal to b'banana', but b'cucumber' given
# --seed 5ecd5919-ea2d-4a5c-b2d4-fc322167f2b4
# 3 scenarios, 0 passed, 1 failed, 2 skipped (0.21s)
info
For more information about Vedro framework, see the documentation.