9595template_coverage_collection = None
9696code_coverage_collection = None
9797url_coverage_collection = None
98-
98+ validation_settings = { "validate_html" : None , "validate_html_harder" : None , "show_logging" : False }
9999
100100def start_vnu_server (port = 8888 ):
101101 "Start a vnu validation server on the indicated port"
@@ -282,7 +282,7 @@ class ValidatingTemplates(DjangoTemplates):
282282 def __init__ (self , params ):
283283 super ().__init__ (params )
284284
285- if not settings . validate_html :
285+ if not validation_settings [ " validate_html" ] :
286286 return
287287 self .validation_cache = set ()
288288 self .cwd = str (pathlib .Path .cwd ())
@@ -298,7 +298,7 @@ def __init__(self, template, backend):
298298 def render (self , context = None , request = None ):
299299 content = super ().render (context , request )
300300
301- if not settings . validate_html :
301+ if not validation_settings [ " validate_html" ] :
302302 return content
303303
304304 if not self .origin .name .endswith ("html" ):
@@ -310,7 +310,7 @@ def render(self, context=None, request=None):
310310 return content
311311
312312 fingerprint = hash (content ) + sys .maxsize + 1 # make hash positive
313- if not settings . validate_html_harder and fingerprint in self .backend .validation_cache :
313+ if not validation_settings [ " validate_html_harder" ] and fingerprint in self .backend .validation_cache :
314314 # already validated this HTML fragment, skip it
315315 # as an optimization, make page a bit smaller by not returning HTML for the menus
316316 # FIXME: figure out why this still includes base/menu.html
@@ -326,7 +326,7 @@ def render(self, context=None, request=None):
326326 # don't validate each template by itself, causes too much overhead
327327 # instead, save a batch of them and then validate them all in one go
328328 # this delays error detection a bit, but is MUCH faster
329- settings . validate_html .batches [kind ].append (
329+ validation_settings [ " validate_html" ] .batches [kind ].append (
330330 (self .origin .name , content , fingerprint )
331331 )
332332 return content
@@ -726,9 +726,10 @@ def __init__(self, ignore_lower_coverage=False, skip_coverage=False, save_versio
726726 self .html_report = html_report
727727 self .permit_mixed_migrations = permit_mixed_migrations
728728 self .show_logging = show_logging
729- settings .validate_html = self if validate_html else None
730- settings .validate_html_harder = self if validate_html and validate_html_harder else None
731- settings .show_logging = show_logging
729+ global validation_settings
730+ validation_settings ["validate_html" ] = self if validate_html else None
731+ validation_settings ["validate_html_harder" ] = self if validate_html and validate_html_harder else None
732+ validation_settings ["show_logging" ] = show_logging
732733 #
733734 self .root_dir = os .path .dirname (settings .BASE_DIR )
734735 self .coverage_file = os .path .join (self .root_dir , settings .TEST_COVERAGE_MAIN_FILE )
@@ -843,7 +844,7 @@ def setup_test_environment(self, **kwargs):
843844 s [1 ] = tuple (s [1 ]) # random.setstate() won't accept a list in lieu of a tuple
844845 factory .random .set_random_state (s )
845846
846- if not settings . validate_html :
847+ if not validation_settings [ " validate_html" ] :
847848 print (" Not validating any generated HTML; "
848849 "please do so at least once before committing changes" )
849850 else :
@@ -912,7 +913,7 @@ def setup_test_environment(self, **kwargs):
912913 self .config_file [kind ].flush ()
913914 pathlib .Path (self .config_file [kind ].name ).chmod (0o644 )
914915
915- if not settings . validate_html_harder :
916+ if not validation_settings [ " validate_html_harder" ] :
916917 print ("" )
917918 self .vnu = None
918919 else :
@@ -941,7 +942,7 @@ def teardown_test_environment(self, **kwargs):
941942 with open (self .coverage_file , "w" ) as file :
942943 json .dump (self .coverage_master , file , indent = 2 , sort_keys = True )
943944
944- if settings . validate_html :
945+ if validation_settings [ " validate_html" ] :
945946 for kind in self .batches :
946947 if len (self .batches [kind ]):
947948 print (f" WARNING: not all templates of kind '{ kind } ' were validated" )
@@ -1007,7 +1008,7 @@ def validate(self, testcase):
10071008 + "\n "
10081009 )
10091010
1010- if settings . validate_html_harder and kind != "frag" :
1011+ if validation_settings [ " validate_html_harder" ] and kind != "frag" :
10111012 files = [
10121013 os .path .join (d , f )
10131014 for d , dirs , files in os .walk (tmppath )
@@ -1084,7 +1085,7 @@ def run_tests(self, test_labels, extra_tests=None, **kwargs):
10841085
10851086 self .test_apps , self .test_paths = self .get_test_paths (test_labels )
10861087
1087- if settings . validate_html :
1088+ if validation_settings [ " validate_html" ] :
10881089 extra_tests += [
10891090 TemplateValidationTests (
10901091 test_runner = self ,
0 commit comments