57
57
CONFIGURATION_ENV = "DJANGO_CONFIGURATION"
58
58
INVALID_TEMPLATE_VARS_ENV = "FAIL_INVALID_TEMPLATE_VARS"
59
59
60
- _report_header = []
61
-
62
60
63
61
# ############### pytest hooks ################
64
62
@@ -257,6 +255,9 @@ def _get_boolean_value(
257
255
)
258
256
259
257
258
+ report_header_key = pytest .StashKey [List [str ]]()
259
+
260
+
260
261
@pytest .hookimpl ()
261
262
def pytest_load_initial_conftests (
262
263
early_config : pytest .Config ,
@@ -330,12 +331,15 @@ def _get_option_with_source(
330
331
ds , ds_source = _get_option_with_source (options .ds , SETTINGS_MODULE_ENV )
331
332
dc , dc_source = _get_option_with_source (options .dc , CONFIGURATION_ENV )
332
333
334
+ report_header : List [str ] = []
335
+ early_config .stash [report_header_key ] = report_header
336
+
333
337
if ds :
334
- _report_header .append (f"settings: { ds } (from { ds_source } )" )
338
+ report_header .append (f"settings: { ds } (from { ds_source } )" )
335
339
os .environ [SETTINGS_MODULE_ENV ] = ds
336
340
337
341
if dc :
338
- _report_header .append (f"configuration: { dc } (from { dc_source } )" )
342
+ report_header .append (f"configuration: { dc } (from { dc_source } )" )
339
343
os .environ [CONFIGURATION_ENV ] = dc
340
344
341
345
# Install the django-configurations importer
@@ -353,20 +357,21 @@ def _get_option_with_source(
353
357
_setup_django ()
354
358
355
359
356
- @pytest .hookimpl ()
357
- def pytest_report_header () -> Optional [List [str ]]:
358
- if _report_header :
359
- return ["django: " + ", " .join (_report_header )]
360
- return None
361
-
362
-
363
360
@pytest .hookimpl (trylast = True )
364
361
def pytest_configure () -> None :
365
362
# Allow Django settings to be configured in a user pytest_configure call,
366
363
# but make sure we call django.setup()
367
364
_setup_django ()
368
365
369
366
367
+ @pytest .hookimpl ()
368
+ def pytest_report_header (config : pytest .Config ) -> Optional [List [str ]]:
369
+ report_header = config .stash [report_header_key ]
370
+ if report_header :
371
+ return ["django: " + ", " .join (report_header )]
372
+ return None
373
+
374
+
370
375
@pytest .hookimpl (tryfirst = True )
371
376
def pytest_collection_modifyitems (items : List [pytest .Item ]) -> None :
372
377
# If Django is not configured we don't need to bother
0 commit comments