Skip to content

Commit a16ee08

Browse files
committed
Improve test a big
1 parent bf011ef commit a16ee08

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

testing/test_gateway.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
mostly functional tests of gateways.
33
"""
44
import os
5+
from textwrap import dedent
6+
57
import py
68
import pytest
79
import socket
@@ -110,19 +112,21 @@ def test_remote_exec_module(self, tmpdir, gw):
110112
name = channel.receive()
111113
assert name == 2
112114

113-
def test_remote_exec_module_with_traceback(self, gw, tmpdir):
115+
def test_remote_exec_module_with_traceback(self, gw, tmpdir, monkeypatch):
114116
remotetest = tmpdir.join("remotetest.py")
115-
remotetest.write(
116-
"\ndef run_me(channel=None):\n raise ValueError('me')\n\n" +
117-
"if __name__ == '__channelexec__':\n run_me()\n")
117+
remotetest.write(dedent("""
118+
def run_me(channel=None):
119+
raise ValueError('me')
118120
119-
try:
120-
sys.path.insert(0, str(tmpdir))
121-
module = __import__("remotetest")
122-
finally:
123-
sys.path.pop(0)
121+
if __name__ == '__channelexec__':
122+
run_me()
123+
""")
124+
)
125+
126+
monkeypatch.syspath_prepend(tmpdir)
127+
import remotetest
124128

125-
ch = gw.remote_exec(module)
129+
ch = gw.remote_exec(remotetest)
126130
try:
127131
ch.receive()
128132
except execnet.gateway_base.RemoteError as e:
@@ -131,7 +135,7 @@ def test_remote_exec_module_with_traceback(self, gw, tmpdir):
131135
finally:
132136
ch.close()
133137

134-
ch = gw.remote_exec(module.run_me)
138+
ch = gw.remote_exec(remotetest.run_me)
135139
try:
136140
ch.receive()
137141
except execnet.gateway_base.RemoteError as e:

0 commit comments

Comments
 (0)