@@ -81,13 +81,15 @@ def test_with_any_microvm(test_microvm_any):
81
81
by the MicrovmImageFetcher, but not by the fixture template.
82
82
"""
83
83
84
+ import inspect
85
+ import json
84
86
import os
85
87
import platform
88
+ import re
86
89
import shutil
87
90
import sys
88
91
import tempfile
89
92
import uuid
90
- import json
91
93
from pathlib import Path
92
94
93
95
import pytest
@@ -101,6 +103,7 @@ def test_with_any_microvm(test_microvm_any):
101
103
from framework .s3fetcher import MicrovmImageS3Fetcher
102
104
from framework .utils import get_firecracker_version_from_toml
103
105
from framework .with_filelock import with_filelock
106
+ from framework .properties import GLOBAL_PROPS
104
107
105
108
# Tests root directory.
106
109
SCRIPT_FOLDER = os .path .dirname (os .path .realpath (__file__ ))
@@ -115,8 +118,6 @@ def test_with_any_microvm(test_microvm_any):
115
118
raise PermissionError ("Test session needs to be run as root." )
116
119
117
120
118
-
119
-
120
121
def _test_images_s3_bucket ():
121
122
"""Auxiliary function for getting this session's bucket name."""
122
123
return os .environ .get (
@@ -234,6 +235,34 @@ def pytest_collection_modifyitems(config, items):
234
235
item .add_marker (skip_marker )
235
236
236
237
238
+ def pytest_runtest_makereport (item , call ):
239
+ """Decorate test results with additional properties."""
240
+ if call .when != "setup" :
241
+ return
242
+
243
+ for prop_name , prop_val in GLOBAL_PROPS .items ():
244
+ # if record_testsuite_property worked with xdist we could use that
245
+ # https://docs.pytest.org/en/7.1.x/reference/reference.html#record-testsuite-property
246
+ # to record the properties once per report. But here we record each
247
+ # prop per test. It just results in larger report files.
248
+ item .user_properties .append ((prop_name , prop_val ))
249
+
250
+ function_docstring = inspect .getdoc (item .function )
251
+ description = []
252
+ attributes = {}
253
+ for line in function_docstring .split ("\n " ):
254
+ # extract tags like @type, @issue, etc
255
+ match = re .match (r"\s*@(?P<attr>\w+):\s*(?P<value>\w+)" , line )
256
+ if match :
257
+ attr , value = match ["attr" ], match ["value" ]
258
+ attributes [attr ] = value
259
+ else :
260
+ description .append (line )
261
+ for attr_name , attr_value in attributes .items ():
262
+ item .user_properties .append ((attr_name , attr_value ))
263
+ item .user_properties .append (("description" , "" .join (description )))
264
+
265
+
237
266
def test_session_root_path ():
238
267
"""Create and return the testrun session root directory.
239
268
0 commit comments