44import json
55import os
66import platform
7+ from typing import Dict , Callable
8+
9+ from pytest import PytestPluginManager , Config , Parser
710
811try :
912 import _pytest ._pluggy as pluggy
3639metadata_key = pytest .StashKey [dict ]()
3740
3841
39- def pytest_addhooks (pluginmanager ) :
42+ def pytest_addhooks (pluginmanager : PytestPluginManager ) -> None :
4043 from pytest_metadata import hooks
4144
4245 pluginmanager .add_hookspecs (hooks )
4346
4447
4548@pytest .fixture (scope = "session" )
46- def metadata (pytestconfig ) :
49+ def metadata (pytestconfig : Config ) -> Dict :
4750 """Provide test session metadata"""
4851 return pytestconfig .stash [metadata_key ]
4952
5053
5154@pytest .fixture (scope = "session" )
52- def include_metadata_in_junit_xml (metadata , pytestconfig , record_testsuite_property ):
55+ def include_metadata_in_junit_xml (
56+ metadata : Dict ,
57+ pytestconfig : Config ,
58+ record_testsuite_property : Callable [[str , object ], None ],
59+ ) -> None :
5360 """Provide test session metadata"""
5461 metadata_ = pytestconfig .stash [metadata_key ]
5562 for name , value in metadata_ .items ():
5663 record_testsuite_property (name , value )
5764
5865
59- def pytest_addoption (parser ) :
66+ def pytest_addoption (parser : Parser ) -> None :
6067 group = parser .getgroup ("pytest-metadata" )
6168 group .addoption (
6269 "--metadata" ,
@@ -83,7 +90,7 @@ def pytest_addoption(parser):
8390
8491
8592@pytest .hookimpl (tryfirst = True )
86- def pytest_configure (config ) :
93+ def pytest_configure (config : Config ) -> None :
8794 config .stash [metadata_key ] = {
8895 "Python" : platform .python_version (),
8996 "Platform" : platform .platform (),
@@ -118,13 +125,15 @@ def pytest_configure(config):
118125 config .hook .pytest_metadata (metadata = config .stash [metadata_key ], config = config )
119126
120127
121- def pytest_report_header (config ) :
128+ def pytest_report_header (config : Config ) -> str | None :
122129 if config .getoption ("verbose" ) > 0 :
123130 return "metadata: {0}" .format (config .stash [metadata_key ])
124131
125132
126133@pytest .hookimpl (optionalhook = True )
127- def pytest_testnodedown (node ):
134+ def pytest_testnodedown (
135+ node : "pytest_xdist.WorkerController" , # noqa: F821
136+ ) -> None : # type:ignore[name-defined]
128137 # note that any metadata from remote workers will be replaced with the
129138 # environment from the final worker to quit
130139 if hasattr (node , "workeroutput" ):
0 commit comments