File tree Expand file tree Collapse file tree 1 file changed +13
-1
lines changed Expand file tree Collapse file tree 1 file changed +13
-1
lines changed Original file line number Diff line number Diff line change 1919    DirectoryPath ,
2020    Discriminator ,
2121    Field ,
22+     RootModel ,
2223    Tag ,
2324    ValidationError ,
2425    field_validator ,
@@ -1778,20 +1779,31 @@ class Settings(BaseSettings):
17781779
17791780
17801781def  test_cli_enforce_required (env ):
1782+     class  MyRootModel (RootModel [str ]):
1783+         root : str 
1784+ 
17811785    class  Settings (BaseSettings , cli_exit_on_error = False ):
17821786        my_required_field : str 
1787+         my_root_model_required_field : MyRootModel 
17831788
17841789    env .set ('MY_REQUIRED_FIELD' , 'hello from environment' )
1790+     env .set ('MY_ROOT_MODEL_REQUIRED_FIELD' , 'hi from environment' )
17851791
17861792    assert  Settings (_cli_parse_args = [], _cli_enforce_required = False ).model_dump () ==  {
1787-         'my_required_field' : 'hello from environment' 
1793+         'my_required_field' : 'hello from environment' ,
1794+         'my_root_model_required_field' : 'hi from environment' ,
17881795    }
17891796
17901797    with  pytest .raises (
17911798        SettingsError , match = 'error parsing CLI: the following arguments are required: --my_required_field' 
17921799    ):
17931800        Settings (_cli_parse_args = [], _cli_enforce_required = True ).model_dump ()
17941801
1802+     with  pytest .raises (
1803+         SettingsError , match = 'error parsing CLI: the following arguments are required: --my_root_model_required_field' 
1804+     ):
1805+         Settings (_cli_parse_args = ['--my_required_field' , 'hello from cli' ], _cli_enforce_required = True ).model_dump ()
1806+ 
17951807
17961808def  test_cli_exit_on_error (capsys , monkeypatch ):
17971809    class  Settings (BaseSettings , cli_parse_args = True ): ...
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments