Skip to main content

Th2 pytest bdd plugin

This is the plugin for pytest, which uses pytest-bdd plugin and th2 as backend.

Features

  • Typed tables in feature file;
  • Th2 client boilerplate isolation (auto th2 access factory creation, events hierarchy creation in background);
  • Test context.

Installation

  • From PyPI
    This package can be found on PyPI.

    pip install pytest-th2-bdd
    
  • From Source

    git clone https://github.com/th2-net/pytest-th2-bdd
    pip install pytest-th2-bdd/
    

Available fixtures

factory

This fixture yields th2 CommonFactory for which will be created from configuration located in configs/ directory.

ctx

This fixture is used for inter-steps communication. It has some important service items:

key purpose
__ROOT__ root events for each feature
__SCENARIO__ current scenario root event
__SCENARIO_START__ current scenario start datetime (in UTC)
__STEP__ current step event

Requirements

  • Prepared th2 test environment;
  • Configuration for th2 CommonFactory in configs/ directory;

How to use tables

Imagine, that you need to pass data as table in some step:

| field1 | field2 | ... | fieldN |
| 1      | 2      | ... | 3      |
...
| valN   | valK   | ... | valM   |
  1. You need to declare dataclass with header definition:
@dataclass
class SomeRow:
    field1: str
    field2: str
    ...
    fieldN: str
  1. Add field and converter at the desired step definition
@given(
    parsers.cfparse(
        "some step description {var1} ... \n{table}",
    ),
    converters={"table": Table(SomeRow)}, # converter setup
)
def some_step(var1, table: Table[SomeRow]): # Syntax hints via generics
    ...

How to start test process (with installed plugin)

pytest tests/

How to start test process (without installed plugin)

export PYTHONPATH=path/to/directory/with/this/repository:$PYTHONPATH
pytest -p th2_bdd.pytest tests/

Metadata

Release files for pytest-th2-bdd 0.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pytest-th2-bdd 0.0.1
File Size Uploaded
pytest_th2_bdd-0.0.1.tar.gz 6.8 kB Details

Release files / pytest_th2_bdd-0.0.1.tar.gz

Download URL pytest_th2_bdd-0.0.1.tar.gz
Size 6.8 kB
Tags Source
SHA-256 checksum
How to use checksums
8d8d873977a4996632eda00b12e4963a9a60c796b34068795e8d742dfb13f7da
BLAKE2b-256 checksum
How to use checksums
c1307073a4dea2d3a180b091acdcce972ba397572aa22bb7f2dcfeeb96fb3b0b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.0 CPython/3.9.12
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page