markers.meta module

meta(**metadata): Marker for metadata addition.

To add metadata to a test simply pass the kwargs as plugins wish.

You can write your own plugins. They generally live in metaplugins/ directory but you can define them pretty much everywhere py.test loads modules. Plugin has a name and a set of callbacks that are called when certain combination of keys is present in the metadata.

To define plugin, do like this:

def someaction(plugin_name):
    print plugin_name  # Will contain value of `plugin_name` key of metadict

This is the simplest usage, where it is supposed that the plugin checks only one key with the same name s the plugin’s name. I won’t use this one in the latter examples, I will use the more verbose one.

@plugin("plugin_name", keys=["plugin_name", "another_key"])
def someaction(plugin_name, another_key):
    print plugin_name  # Will contain value of `plugin_name` key of metadict
    print another_key  # Similarly this one

This one reacts when the two keys are present. You can make even more complex setups:

@plugin("plugin_name", keys=["plugin_name"])
@plugin("plugin_name", ["plugin_name", "another_key"])  # You don't have to write keys=
def someaction(plugin_name, another_key=None):
    print plugin_name  # Will contain value of `plugin_name` key of metadict
    print another_key  # Similarly this one if specified, otherwise None

This created a nonrequired parameter for the action.

You can specify as many actions as you wish per plugin. The only thing that limits you is the correct action choice. First, all the actions are filtered by present keys in metadata. Then after this selection, only the action with the most matched keywords is called. Bear this in your mind. If this is not enough in the future, it can be extended if you wish.

It has a command-line option that allows you to disable certain plugins. Just specify --disablemetaplugins a,b,c where a, b and c are the plugins that should be disabled

class markers.meta.Plugin

Bases: tuple

Plugin(name, metas, function, kwargs)


Alias for field number 2


Alias for field number 3


Alias for field number 1


Alias for field number 0

class markers.meta.PluginContainer[source]

Bases: object

AFTER_RUN = 'after_run'
BEFORE_RUN = 'before_run'
DEFAULT = 'setup'
SETUP = 'setup'
TEARDOWN = 'teardown'
markers.meta.pytest_collection_modifyitems(session, config, items)[source]
markers.meta.pytest_pycollect_makeitem(collector, name, obj)[source]
markers.meta.run_plugins(item, when)[source]