playbook

A plugin for creating, validating, and reading a playbook.

Use the pytest_playbook_schema() hook to modify the schema dictionary representing the data expected to be read and validated from a playbook.yaml YAML file, the path to which is provided by the user with the command-line flag --playbook=<data.yaml>.

This module’s data attribute will hold the read and validated data after all pytest_configure() hooks have run. Use it in your conftest.py (or Pytest plugin) like so:

import playbook
from schema import Schema

def pytest_playbook_schema(schema):
    schema["targets"] = Schema({"name": str, "platform": str, "cpus": int})

def pytest_sessionstart(session):
    for target in playbook.data["targets"]:
        print(target["name"])

Remember not to use from playbook import data because then the attribute will not contain the shared data. Instead use import playbook and reference playbook.data.

All registered schema can be printed to a JSON Schema file with --print-schema=<file.json>.

Module Attributes

data

This global is the data read from the given playbook.

Functions

pytest_addhooks(pluginmanager)

Pytest addhooks hook to register our hooks.

pytest_addoption(parser, pluginmanager)

Pytest addoption hook to add our CLI options.

pytest_configure(config)

Pytest configure hook to configure our plugin.

Classes

Hooks()

Provides the hook specifications.

playbook.data: Dict[Any, Any] = {}[source]

This global is the data read from the given playbook.

class playbook.Hooks[source][source]

Bases: object

Provides the hook specifications.

pytest_playbook_schema(schema: Dict[Any, Any], config: Config) → None[source][source]

Update the Playbook’s schema dict.

Parameters
  • schema – mutable dict passed to schema.validate() in pytest_configure().

  • config – optional, allows access to Pytest Config object if given.

playbook.pytest_addhooks(pluginmanager: PytestPluginManager) → None[source][source]

Pytest addhooks hook to register our hooks.

playbook.pytest_addoption(parser: Parser, pluginmanager: PytestPluginManager) → None[source][source]

Pytest addoption hook to add our CLI options.

playbook.pytest_configure(config: Config) → None[source][source]

Pytest configure hook to configure our plugin.

This is set to be tried last so that all other plugins and conftest.py files have been loaded and defined their pytest_playbook_schema() hooks.