Skip to content

Commit 2b5952c

Browse files
jakkdlbluetech
authored andcommitted
testing: avoid legacy forms of warns, raises, deprecated_call
Use the nicer `with` forms instead.
1 parent fa643de commit 2b5952c

21 files changed

Lines changed: 252 additions & 144 deletions

testing/_py/test_local.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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

testing/code/test_code.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,8 @@ def test_code_from_func() -> None:
8585
def test_unicode_handling() -> None:
8686
value = "ąć".encode()
8787

88-
def f() -> None:
89-
raise ValueError(value)
90-
91-
excinfo = pytest.raises(ValueError, f)
88+
with pytest.raises(Exception) as excinfo:
89+
raise Exception(value)
9290
str(excinfo)
9391

9492

0 commit comments

Comments
 (0)