from pytest_pilot import EasyMarker flavour = EasyMarker('flavour', allowed_values=('red', 'yellow'), mode='hard_filter')
def pytest_load_initial_conftests(early_config, parser, args): """ Adds the options corresponding to all declared markers :param parser: :return: """ # first let the loading happen yield # then call the extra hook to know what the user wants results = early_config.pluginmanager.hook.pytest_pilot_markers() nb_plugin_that_answered_with_a_non_none = len(results) global all_markers assert nb_plugin_that_answered_with_a_non_none < 2, "should not happen since our hook has first_results == True" if nb_plugin_that_answered_with_a_non_none == 0: # default behaviour: register all markers created by users all_markers = EasyMarker.list_all() else: all_markers = results[0] # existing options existing_opts = vars(early_config.option) # then add the options accordingly for marker in all_markers: # For long names (and sometimes short ones too?) the conflict # does not raise an error in pytest when adding the option, therefore # we try to provide some early detection here. short_exists = marker.cmdoption_short.strip( '-' ) in existing_opts if marker.cmdoption_short is not None else False long_exists = marker.cmdoption_long.strip('-') in existing_opts if short_exists or long_exists: conflicting = [] if short_exists: conflicting.append(marker.cmdoption_short) if long_exists: conflicting.append(marker.cmdoption_long) raise ValueError( "Error registering <%s>: a command with this long or short name already exists." " Conflicting name(s): %s" % (marker, conflicting)) # No long name conflict. add option and catch short name conflicts names = [] if marker.cmdoption_short is not None: names.append(marker.cmdoption_short) if marker.cmdoption_long is not None: names.append(marker.cmdoption_long) try: if marker.has_arg: parser.addoption(*names, action="store", metavar="NAME", help=marker.cmdhelp) else: parser.addoption(*names, action="store_true", help=marker.cmdhelp) except Exception as e: raise ValueError( "Error registering <%s>: a command with this long or short name already exists. " "Caught: %r" % (marker, e))
from pytest_pilot import EasyMarker envid = EasyMarker('envid', has_arg=False, mode='silos')
from pytest_pilot import EasyMarker silo = EasyMarker("silo", cmdoption_short="-Z", mode="silos", has_arg=False) # note : using a name different from the command name is not really a good practice... hardfilter = EasyMarker("hf", mode="hard_filter", has_arg=False) envid = EasyMarker("envid", full_name="environment", mode="extender") flavour = EasyMarker("flavour", allowed_values=("red", "yellow"), mode="soft_filter")
from pytest_pilot import EasyMarker envid = EasyMarker('envid', mode='hard_filter') slow = EasyMarker('slow', has_arg=False, mode='extender')
from pytest_pilot import EasyMarker slow = EasyMarker('slow', has_arg=False, mode='extender')
from pytest_pilot import EasyMarker envid = EasyMarker('envid', mode='silos')