A simple BDD library for testing python code.
Project description
simple-bdd
A BDD library for testing python code that puts simplicity over magic features.
BDD testing is a great way to provide structure and context to your tests. It helps facilitate readability and reuse of common functions. The purpose of this library is to provide a quick and simple way to create BDD style tests in python. It is not intended to generate documentation or to use Gherkin files but rather to help developers in creating simple tests using BDD.
Installation
Pip
pip install simple-bdd
Poetry
poetry add simple-bdd
Usage
Test Setup
Tests are split into two files the specs file and the steps file.
Specs files should end with '_specs_test'.
Steps files should mirror the specs file name but with '_steps' instead of '_specs_test'.
Example:
For the files:
- simple_bdd_test.py
- simple_bdd_spec.py
In your steps file add a reference to the simple-bdd library.
from bdd import *
Then add a reference to the steps file in your specs file like below:
from simple_bdd_spec import *
Test Creation
Tests are created using basic Gherkin syntax. You can use the following Gherkin methods:
Given()
When()
Then()
And()
To create a test start by creating a method prefixed with 'test_'. Inside the method using Gherkin syntax create your test spec. See example below:
Example:
def test_that_when_we_do_something_something_is_true():
Given(something)
When(we_do_something)
Then(the_something_is_true)
Next in your steps file we need to define the steps for the spec to call.
[!NOTE]
You will need to pass the context object into your method. See Context for more details.
def something(context: BddContext):
context.something = 'something'
def we_do_something(context: BddContext):
context.result = (context.something == 'something')
def the_something_is_true(context: BddContext):
assert context.result == True
Context
To pass data between steps we use the context object. This allows test steps to remain independent and be reused else where in your testing.
Write value
context.something = 'something'
Read value
print(context.something)
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
File details
Details for the file simple_bdd-0.2.0.tar.gz
.
File metadata
- Download URL: simple_bdd-0.2.0.tar.gz
- Upload date:
- Size: 3.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.10.12 Linux/6.5.0-1022-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b95d09486235d6c7dd41888344b3bbafd4a4f2d5769c4a96fd3e3fdb371c92a1 |
|
MD5 | 5373681e4b8e8a3a8a48418725bb1775 |
|
BLAKE2b-256 | e990c4ed2f861cce1a5dc87a4c54f1d78f461d94f5b69e47a3965c071b5526e6 |
File details
Details for the file simple_bdd-0.2.0-py3-none-any.whl
.
File metadata
- Download URL: simple_bdd-0.2.0-py3-none-any.whl
- Upload date:
- Size: 3.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.10.12 Linux/6.5.0-1022-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 55226820ee88dff43bd5f778bd48a9d6fb6fdf1455573e8859c33c8b3acc2852 |
|
MD5 | 10b15180c8603dc12e0ab2df9bf97019 |
|
BLAKE2b-256 | 68a67153040c862f33210f7f88371ef3c037b923197ba49c706dd26019e419c5 |