@@ -465,6 +465,44 @@ def test_sitecustomize_executed(self):
465
465
else :
466
466
self .fail ("sitecustomize not imported automatically" )
467
467
468
+ @support .requires_subprocess ()
469
+ def test_customization_modules_on_startup (self ):
470
+ mod_names = [
471
+ 'sitecustomize'
472
+ ]
473
+
474
+ if site .ENABLE_USER_SITE :
475
+ mod_names .append ('usercustomize' )
476
+
477
+ temp_dir = tempfile .mkdtemp ()
478
+ self .addCleanup (os_helper .rmtree , temp_dir )
479
+
480
+ with EnvironmentVarGuard () as environ :
481
+ environ ['PYTHONPATH' ] = temp_dir
482
+
483
+ for module_name in mod_names :
484
+ os_helper .rmtree (temp_dir )
485
+ os .mkdir (temp_dir )
486
+
487
+ customize_path = os .path .join (temp_dir , f'{ module_name } .py' )
488
+ eyecatcher = f'EXECUTED_{ module_name } '
489
+
490
+ with open (customize_path , 'w' ) as f :
491
+ f .write (f'print("{ eyecatcher } ")' )
492
+
493
+ output = subprocess .check_output ([sys .executable , '-c' , '""' ])
494
+ self .assertIn (eyecatcher , output .decode ('utf-8' ))
495
+
496
+ # -S blocks any site-packages
497
+ output = subprocess .check_output ([sys .executable , '-S' , '-c' , '""' ])
498
+ self .assertNotIn (eyecatcher , output .decode ('utf-8' ))
499
+
500
+ # -s blocks user site-packages
501
+ if 'usercustomize' == module_name :
502
+ output = subprocess .check_output ([sys .executable , '-s' , '-c' , '""' ])
503
+ self .assertNotIn (eyecatcher , output .decode ('utf-8' ))
504
+
505
+
468
506
@unittest .skipUnless (hasattr (urllib .request , "HTTPSHandler" ),
469
507
'need SSL support to download license' )
470
508
@test .support .requires_resource ('network' )
0 commit comments