"""Integration helpers for behave's ``environment.py``.``before_all`` and ``after_scenario`` can be imported directly as behavehooks. ``before_scenario`` must be written by the user (it calls``context.steplib.reset()``).Usage:: # features/environment.py from steplib.behave import after_scenario, before_all def before_scenario(context, scenario): context.steplib.reset()"""from__future__importannotationsfromtypingimportAnyfromsteplib.core.discoveryimportautoloadas_autoloadfromsteplib.core.discoveryimportloadas_loadfromsteplib.core.stateimportSteplibState__all__=["SteplibState","after_scenario","autoload","before_all","load"]
[docs]defautoload(context:Any,categories:list[str]|None=None,backends:dict[str,str]|None=None,)->SteplibState:"""Load all installed steplib plugins and attach state to *context*. See :func:`steplib.core.discovery.autoload` for details. Args: context: The behave context object. categories: Optional list of categories to keep (e.g. ``["api"]``). backends: Optional mapping of category to backend (e.g. ``{"api": "httpx"}``). Returns: A ``SteplibState`` holding the filtered registry. """return_autoload(context,categories=categories,backends=backends)
[docs]defload(context:Any,*modules:str)->SteplibState:"""Load specific step modules by dotted path. See :func:`steplib.core.discovery.load` for details. Args: context: The behave context object. *modules: Dotted module paths to import. Returns: A ``SteplibState`` holding the registry. """return_load(context,*modules)
[docs]defbefore_all(context:Any)->SteplibState:"""Run autoload and attach steplib state to *context*. Args: context: The behave context object. Returns: The ``SteplibState`` attached to ``context.steplib``. """state=autoload(context)context.steplib=statereturnstate
[docs]defafter_scenario(context:Any,scenario:Any)->None:"""Clean up steplib resources after a scenario. Args: context: The behave context object. scenario: The behave scenario object (unused but required by the hook). """state=getattr(context,"steplib",None)ifstateisnotNoneandhasattr(state,"cleanup"):state.cleanup()