@@ -620,7 +620,8 @@ def test_chdir_gone(self, path1):
620620 p = path1 .ensure ("dir_to_be_removed" , dir = 1 )
621621 p .chdir ()
622622 p .remove ()
623- pytest .raises (error .ENOENT , local )
623+ with pytest .raises (error .ENOENT ):
624+ local ()
624625 assert path1 .chdir () is None
625626 assert os .getcwd () == str (path1 )
626627
@@ -989,8 +990,10 @@ def test_locked_make_numbered_dir(self, tmpdir):
989990 assert numdir .new (ext = str (j )).check ()
990991
991992 def test_error_preservation (self , path1 ):
992- pytest .raises (EnvironmentError , path1 .join ("qwoeqiwe" ).mtime )
993- pytest .raises (EnvironmentError , path1 .join ("qwoeqiwe" ).read )
993+ with pytest .raises (EnvironmentError ):
994+ path1 .join ("qwoeqiwe" ).mtime ()
995+ with pytest .raises (EnvironmentError ):
996+ path1 .join ("qwoeqiwe" ).read ()
994997
995998 # def test_parentdirmatch(self):
996999 # local.parentdirmatch('std', startmodule=__name__)
@@ -1090,7 +1093,8 @@ def test_pyimport_check_filepath_consistency(self, monkeypatch, tmpdir):
10901093 pseudopath = tmpdir .ensure (name + "123.py" )
10911094 mod .__file__ = str (pseudopath )
10921095 monkeypatch .setitem (sys .modules , name , mod )
1093- excinfo = pytest .raises (pseudopath .ImportMismatchError , p .pyimport )
1096+ with pytest .raises (pseudopath .ImportMismatchError ) as excinfo :
1097+ p .pyimport ()
10941098 modname , modfile , orig = excinfo .value .args
10951099 assert modname == name
10961100 assert modfile == pseudopath
@@ -1388,7 +1392,8 @@ def test_stat_helpers(self, tmpdir, monkeypatch):
13881392
13891393 def test_stat_non_raising (self , tmpdir ):
13901394 path1 = tmpdir .join ("file" )
1391- pytest .raises (error .ENOENT , path1 .stat )
1395+ with pytest .raises (error .ENOENT ):
1396+ path1 .stat ()
13921397 res = path1 .stat (raising = False )
13931398 assert res is None
13941399
0 commit comments