3131 travis_ci .ENVIRONMENT_VARIABLES ,
3232]
3333
34+ metadata_key = pytest .StashKey [dict ]()
35+
3436
3537def pytest_addhooks (pluginmanager ):
3638 from . import hooks
@@ -41,13 +43,13 @@ def pytest_addhooks(pluginmanager):
4143@pytest .fixture (scope = "session" )
4244def metadata (pytestconfig ):
4345 """Provide test session metadata"""
44- return pytestconfig ._metadata
46+ return pytestconfig .stash [ metadata_key ]
4547
4648
4749@pytest .fixture (scope = "session" )
4850def include_metadata_in_junit_xml (metadata , pytestconfig , record_testsuite_property ):
4951 """Provide test session metadata"""
50- metadata_ = pytestconfig ._metadata
52+ metadata_ = pytestconfig .stash [ metadata_key ]
5153 for name , value in metadata_ .items ():
5254 record_testsuite_property (name , value )
5355
@@ -79,46 +81,47 @@ def pytest_addoption(parser):
7981
8082@pytest .hookimpl (tryfirst = True )
8183def pytest_configure (config ):
82- config ._metadata = {
84+ config .stash [ metadata_key ] = {
8385 "Python" : platform .python_version (),
8486 "Platform" : platform .platform (),
8587 "Packages" : {
8688 "pytest" : pytest .__version__ ,
8789 "pluggy" : pluggy .__version__ ,
8890 },
8991 }
90- config ._metadata .update ({k : v for k , v in config .getoption ("metadata" )})
91- config ._metadata .update (json .loads (config .getoption ("metadata_from_json" )))
92+ config .stash [metadata_key ].update ({k : v for k , v in config .getoption ("metadata" )})
93+ config .stash [metadata_key ].update (
94+ json .loads (config .getoption ("metadata_from_json" ))
95+ )
9296 if config .getoption ("metadata_from_json_file" ):
9397 with open (config .getoption ("metadata_from_json_file" ), "r" ) as json_file :
94- config ._metadata .update (json .load (json_file ))
98+ config .stash [ metadata_key ] .update (json .load (json_file ))
9599 plugins = dict ()
96100 for plugin , dist in config .pluginmanager .list_plugin_distinfo ():
97101 name , version = dist .project_name , dist .version
98102 if name .startswith ("pytest-" ):
99103 name = name [7 :]
100104 plugins [name ] = version
101- config ._metadata ["Plugins" ] = plugins
105+ config .stash [ metadata_key ] ["Plugins" ] = plugins
102106
103107 for provider in CONTINUOUS_INTEGRATION :
104108 for var in provider :
105109 if os .environ .get (var ):
106- config ._metadata .update ({var : os .environ .get (var )})
110+ config .stash [ metadata_key ] .update ({var : os .environ .get (var )})
107111
108112 if hasattr (config , "workeroutput" ):
109- config .workeroutput ["metadata" ] = config ._metadata
110-
111- config .hook .pytest_metadata (metadata = config ._metadata )
113+ config .workeroutput ["metadata" ] = config .stash [metadata_key ]
114+ config .hook .pytest_metadata (metadata = config .stash [metadata_key ], config = config )
112115
113116
114117def pytest_report_header (config ):
115118 if config .getoption ("verbose" ) > 0 :
116- return "metadata: {0}" .format (config ._metadata )
119+ return "metadata: {0}" .format (config .stash [ metadata_key ] )
117120
118121
119122@pytest .hookimpl (optionalhook = True )
120123def pytest_testnodedown (node ):
121124 # note that any metadata from remote workers will be replaced with the
122125 # environment from the final worker to quit
123126 if hasattr (node , "workeroutput" ):
124- node .config ._metadata .update (node .workeroutput ["metadata" ])
127+ node .config .stash [ metadata_key ] .update (node .workeroutput ["metadata" ])
0 commit comments