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
This global is the data read from the given playbook. |
Functions
|
Pytest addhooks hook to register our hooks. |
|
Pytest addoption hook to add our CLI options. |
|
Pytest configure hook to configure our plugin. |
Classes
|
Provides the hook specifications. |
-
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()
inpytest_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 theirpytest_playbook_schema()
hooks.