File tree Expand file tree Collapse file tree 1 file changed +5
-6
lines changed Expand file tree Collapse file tree 1 file changed +5
-6
lines changed Original file line number Diff line number Diff line change @@ -367,19 +367,18 @@ def test_get_user(monkeypatch):
367367    assert  get_user () is  None 
368368
369369
370+ @pytest .mark .skipif (not  sys .platform .startswith ("win" ), reason = "win only" ) 
370371def  test_get_user_handles_oserror (monkeypatch ):
371372    """Test that get_user() returns None when getpass.getuser() raises OSError. 
372373     
373374    This handles the Python 3.13+ behavior where getpass.getuser() raises 
374375    OSError when no username environment variables (LOGNAME, USER, LNAME, 
375376    USERNAME) are set on Windows (#11874). 
376377    """ 
377-     import  getpass 
378- 
379-     def  mock_getuser ():
380-         raise  OSError ("No username set in the environment" )
381- 
382-     monkeypatch .setattr (getpass , "getuser" , mock_getuser )
378+     monkeypatch .delenv ("LOGNAME" , raising = False )
379+     monkeypatch .delenv ("USER" , raising = False )
380+     monkeypatch .delenv ("LNAME" , raising = False )
381+     monkeypatch .delenv ("USERNAME" , raising = False )
383382    assert  get_user () is  None 
384383
385384
    
 
   
 
     
   
   
          
     
  
    
     
 
    
      
     
 
     
    You can’t perform that action at this time.
  
 
    
  
     
    
      
        
     
 
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments