tursu.entrypoints.plugin

Pytest plugin

Module Contents

Classes

GherkinTestModule

A pytest collector made for gherkin .scenario files.

Functions

build_pkg

tursu

Fixture used in generated test module to access to the runtime part.

tursu_collect_file

Used to generate a pytest_collect_file() function in a conftest.py file.

API

class tursu.entrypoints.plugin.GherkinTestModule(path: pathlib.Path, tursu: tursu.runtime.registry.Tursu, parent: pytest.Module | None = None, **kwargs: Any)

Bases: pytest.Module

A pytest collector made for gherkin .scenario files.

While collecting, it generate ast code to run tests using the python runtime.

Parameters:
  • path – test root directory.

  • tursu – the tursu registry to register steps.

  • **kwargs – pytest extra parameters.

Initialization

__repr__() str
collect() collections.abc.Iterable[pytest.Item | pytest.Collector]

Will collect the scenario as an AST generated module.

tursu.entrypoints.plugin.build_pkg(node: Any) str
tursu.entrypoints.plugin.tursu() tursu.runtime.registry.Tursu

Fixture used in generated test module to access to the runtime part.

Tursu generate bytecode for running scenario. The bytecode is simple, and is designed to be highly debuggable.

Tursu object is the registry of the steps definition that can be used at runtime to match those definition and run their associated hook.

tursu.entrypoints.plugin.tursu_collect_file() None

Used to generate a pytest_collect_file() function in a conftest.py file.

pytest comes with a hook pytest_collect_file used to collect tests that tursu use to generate the tests suite from Gherkin files.

A conftest.py has to be created with in the same directory structure of .scenario file containing tursu_collect_file(). A parent conftest.py file can exists in order to have shared fixtures between multiple tests suite.

Minimal Function Tests Directory Structure:

tests/functionals/
│── __init__.py        # Must be present for the scenarios discovery.
│── conftest.py        # Must contains `tursu_collect_file()`
│── example.scenario   # Gherkin scenario file
│── steps.py           # Step definitions for Gherkin scenarios

It is also possible to nest scenario and scope steps definition per module. To get advanced directory structure, read the project layout chapter from the documentation.