def pytest_configure(config: Config) -> None: """ Register the "order" marker and configure the plugin, depending on the CLI options. """ provided_by_pytest_order = ( "Provided by pytest-order. " "See also: https://pytest-dev.github.io/pytest-order/" ) config_line = ( "order: specify ordering information for when tests should run " "in relation to one another. " + provided_by_pytest_order ) config.addinivalue_line("markers", config_line) # We need to dynamically add this `tryfirst` decorator to the plugin: # only when the CLI option is present should the decorator be added. # Thus, we manually run the decorator on the class function and # manually replace it. if config.getoption("indulgent_ordering"): wrapper = pytest.hookimpl(tryfirst=True) else: wrapper = pytest.hookimpl(trylast=True) setattr( OrderingPlugin, "pytest_collection_modifyitems", wrapper(modify_items) ) config.pluginmanager.register(OrderingPlugin(), "orderingplugin")
def pytest_configure(config): """Register the "order" marker and configure the plugin depending on the CLI options""" provided_by_pytest_order = ( "Provided by pytest-order. " "See also: https://mrbean-bremen.github.io/pytest-order/") config_line = ( "order: specify ordering information for when tests should run " "in relation to one another. " + provided_by_pytest_order) config.addinivalue_line("markers", config_line) if config.getoption("indulgent_ordering"): # We need to dynamically add this `tryfirst` decorator to the plugin: # only when the CLI option is present should the decorator be added. # Thus, we manually run the decorator on the class function and # manually replace it. # Python 2.7 didn"t allow arbitrary attributes on methods, so we have # to keep the function as a function and then add it to the class as a # pseudomethod. Since the class is purely for structuring and `self` # is never referenced, this seems reasonable. OrderingPlugin.pytest_collection_modifyitems = pytest.hookimpl( function=modify_items, tryfirst=True) else: OrderingPlugin.pytest_collection_modifyitems = pytest.hookimpl( function=modify_items, trylast=True) config.pluginmanager.register(OrderingPlugin(), "orderingplugin")
def pytest_configure(config): """Register the "run" marker and configure the plugin depending on the CLI options""" provided_by_pytest_ordering = ( 'Provided by pytest-ordering. ' 'See also: http://pytest-ordering.readthedocs.org/') config_line = ( 'run: specify ordering information for when tests should run ' 'in relation to one another. ' + provided_by_pytest_ordering) config.addinivalue_line('markers', config_line) for mark_name in orders_map.keys(): config_line = '{}: run test {}. {}'.format( mark_name, mark_name.replace('_', ' '), provided_by_pytest_ordering) config.addinivalue_line('markers', config_line) if config.getoption('indulgent-ordering'): # We need to dynamically add this `tryfirst` decorator to the plugin: # only when the CLI option is present should the decorator be added. # Thus, we manually run the decorator on the class function and # manually replace it. # Python 2.7 didn't allow arbitrary attributes on methods, so we have # to keep the function as a function and then add it to the class as a # pseudomethod. Since the class is purely for structuring and `self` # is never referenced, this seems reasonable. OrderingPlugin.pytest_collection_modifyitems = pytest.hookimpl( function=modify_items, tryfirst=True) else: OrderingPlugin.pytest_collection_modifyitems = pytest.hookimpl( function=modify_items, trylast=True) config.pluginmanager.register(OrderingPlugin(), 'orderingplugin')
def pytest_benchmark_compare_machine_info(config, benchmarksession, machine_info, compared_benchmark): if compared_benchmark["machine_info"] != machine_info: benchmarksession.logger.warn( "BENCHMARK-C6", "Benchmark machine_info is different. Current: %s VS saved: %s." % ( format_dict(machine_info), format_dict(compared_benchmark["machine_info"]), ), fslocation=benchmarksession.storage.location) if hasattr(pytest, 'hookimpl'): _hookwrapper = pytest.hookimpl(hookwrapper=True) else: _hookwrapper = pytest.mark.hookwrapper @_hookwrapper def pytest_runtest_call(item): bs = item.config._benchmarksession fixure = hasattr(item, "funcargs") and item.funcargs.get("benchmark") if isinstance(fixure, BenchmarkFixture): if bs.skip: pytest.skip("Skipping benchmark (--benchmark-skip active).") else: yield else: if bs.only:
def inner(f): return pytest.hookimpl(hookwrapper=True, **kwargs)(_with_hub(f))
def pytest_benchmark_compare_machine_info(config, benchmarksession, machine_info, compared_benchmark): machine_info = format_dict(machine_info) compared_machine_info = format_dict(compared_benchmark["machine_info"]) if compared_machine_info != machine_info: benchmarksession.logger.warn( "BENCHMARK-C6", "Benchmark machine_info is different. Current: %s VS saved: %s." % ( machine_info, compared_machine_info, ), fslocation=benchmarksession.storage.location ) if hasattr(pytest, 'hookimpl'): _hookwrapper = pytest.hookimpl(hookwrapper=True) else: _hookwrapper = pytest.mark.hookwrapper @_hookwrapper def pytest_runtest_call(item): bs = item.config._benchmarksession fixure = hasattr(item, "funcargs") and item.funcargs.get("benchmark") if isinstance(fixure, BenchmarkFixture): if bs.skip: pytest.skip("Skipping benchmark (--benchmark-skip active).") else: yield else: if bs.only:
import pytest try: from _pytest.cacheprovider import Cache except ImportError: from pytest_cache import Cache if hasattr(pytest, 'hookimpl'): tryfirst = pytest.hookimpl(tryfirst=True) else: tryfirst = pytest.mark.tryfirst