Skip to content

Commit 60b235c

Browse files
committed
Update deprecated pytest.raises(..., 'str-as-code') to modern equivalent
1 parent 189fada commit 60b235c

File tree

6 files changed

+34
-24
lines changed

6 files changed

+34
-24
lines changed

testing/test_basics.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -385,8 +385,10 @@ def func(channel, data):
385385

386386
def test_remote_exc__no_kwargs(makegateway):
387387
gw = makegateway()
388-
pytest.raises(TypeError, gw.remote_exec, gateway_base, kwarg=1)
389-
pytest.raises(TypeError, gw.remote_exec, 'pass', kwarg=1)
388+
with pytest.raises(TypeError):
389+
gw.remote_exec(gateway_base, kwarg=1)
390+
with pytest.raises(TypeError):
391+
gw.remote_exec('pass', kwarg=1)
390392

391393

392394
@skip_win_pypy

testing/test_channel.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ def test_waitclose_timeouterror(self, gw):
3737

3838
def test_channel_receive_timeout(self, gw):
3939
channel = gw.remote_exec('channel.send(channel.receive())')
40-
pytest.raises(channel.TimeoutError, "channel.receive(timeout=0.2)")
40+
with pytest.raises(channel.TimeoutError):
41+
channel.receive(timeout=0.2)
4142
channel.send(1)
4243
channel.receive(timeout=TESTTIMEOUT)
4344

@@ -263,9 +264,8 @@ def f(item):
263264
""")
264265
subchan = channel.receive()
265266
subchan.send(1)
266-
excinfo = pytest.raises(
267-
subchan.RemoteError,
268-
"subchan.waitclose(TESTTIMEOUT)")
267+
with pytest.raises(subchan.RemoteError) as excinfo:
268+
subchan.waitclose(TESTTIMEOUT)
269269
assert "42" in excinfo.value.formatted
270270
channel.send(1)
271271
channel.waitclose()
@@ -289,7 +289,8 @@ def test_channel_file_write_error(self, gw):
289289
f = channel.makefile()
290290
assert not f.isatty()
291291
channel.waitclose(TESTTIMEOUT)
292-
pytest.raises(IOError, f.write, 'hello')
292+
with pytest.raises(IOError):
293+
f.write('hello')
293294

294295
def test_channel_file_proxyclose(self, gw):
295296
channel = gw.remote_exec("""

testing/test_gateway.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,8 @@ def test_remote_exec_error_after_close(self, gw):
138138

139139
def test_remote_exec_no_explicit_close(self, gw):
140140
channel = gw.remote_exec('channel.close()')
141-
excinfo = py.test.raises(
142-
channel.RemoteError,
143-
"channel.waitclose(TESTTIMEOUT)")
141+
with pytest.raises(channel.RemoteError) as excinfo:
142+
channel.waitclose(TESTTIMEOUT)
144143
assert "explicit" in excinfo.value.formatted
145144

146145
def test_remote_exec_channel_anonymous(self, gw):
@@ -218,9 +217,8 @@ def test_chdir_separation(self, tmpdir, makegateway):
218217
assert x.lower() == str(waschangedir).lower()
219218

220219
def test_remoteerror_readable_traceback(self, gw):
221-
e = py.test.raises(
222-
gateway_base.RemoteError,
223-
'gw.remote_exec("x y").waitclose()')
220+
with pytest.raises(gateway_base.RemoteError) as e:
221+
gw.remote_exec("x y").waitclose()
224222
assert "gateway_base" in e.value.formatted
225223

226224
def test_many_popen(self, makegateway):
@@ -253,9 +251,12 @@ def test_waitclose_on_remote_killed(self, makegateway):
253251
""")
254252
remotepid = channel.receive()
255253
py.process.kill(remotepid)
256-
py.test.raises(EOFError, "channel.waitclose(TESTTIMEOUT)")
257-
py.test.raises(IOError, channel.send, None)
258-
py.test.raises(EOFError, channel.receive)
254+
with pytest.raises(EOFError):
255+
channel.waitclose(TESTTIMEOUT)
256+
with pytest.raises(IOError):
257+
channel.send(None)
258+
with pytest.raises(EOFError):
259+
channel.receive()
259260

260261
def test_receive_on_remote_sysexit(self, gw):
261262
channel = gw.remote_exec("""
@@ -371,8 +372,8 @@ def test_status_with_threads(self, makegateway):
371372
class TestTracing:
372373
def test_popen_filetracing(self, testdir, monkeypatch, makegateway):
373374
tmpdir = testdir.tmpdir
374-
monkeypatch.setenv("TMP", tmpdir)
375-
monkeypatch.setenv("TEMP", tmpdir) # windows
375+
monkeypatch.setenv("TMP", str(tmpdir))
376+
monkeypatch.setenv("TEMP", str(tmpdir)) # windows
376377
monkeypatch.setenv('EXECNET_DEBUG', "1")
377378
gw = makegateway("popen")
378379
# hack out the debuffilename

testing/test_multi.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,14 +176,17 @@ def test_gateway_and_id(self):
176176
group = Group()
177177
gw = group.makegateway("popen//id=hello")
178178
assert group["hello"] == gw
179-
py.test.raises((TypeError, AttributeError), "del group['hello']")
180-
py.test.raises((TypeError, AttributeError), "group['hello'] = 5")
179+
with pytest.raises((TypeError, AttributeError)):
180+
del group['hello']
181+
with pytest.raises((TypeError, AttributeError)):
182+
group['hello'] = 5
181183
assert 'hello' in group
182184
assert gw in group
183185
assert len(group) == 1
184186
gw.exit()
185187
assert 'hello' not in group
186-
py.test.raises(KeyError, "group['hello']")
188+
with pytest.raises(KeyError):
189+
_ = group['hello']
187190

188191
def test_default_group(self):
189192
oldlist = list(execnet.default_group)

testing/test_rsync.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,14 @@ def test_dirsync_twice(self, dirs, gw1, gw2):
9090
rsync.add_target(gw1, dirs.dest1)
9191
rsync.send()
9292
assert dirs.dest1.join('hello').check()
93-
py.test.raises(IOError, "rsync.send()")
93+
with pytest.raises(IOError):
94+
rsync.send()
9495
assert rsync.send(raises=False) is None
9596
rsync.add_target(gw1, dirs.dest2)
9697
rsync.send()
9798
assert dirs.dest2.join('hello').check()
98-
py.test.raises(IOError, "rsync.send()")
99+
with pytest.raises(IOError):
100+
rsync.send()
99101
assert rsync.send(raises=False) is None
100102

101103
def test_rsync_default_reporting(self, capsys, dirs, gw1):

testing/test_xspec.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ def test_norm_attributes(self):
2323
assert spec.nice is None
2424
assert not hasattr(spec, '_xyz')
2525

26-
pytest.raises(AttributeError, "spec._hello")
26+
with pytest.raises(AttributeError):
27+
spec._hello()
2728

2829
spec = XSpec("socket=192.168.102.2:8888//python=python2.5//nice=3")
2930
assert spec.socket == "192.168.102.2:8888"

0 commit comments

Comments
 (0)