diff --git a/py/execnet/gateway.py b/py/execnet/gateway.py index 2c7df7e11..b95d85bb8 100644 --- a/py/execnet/gateway.py +++ b/py/execnet/gateway.py @@ -241,16 +241,18 @@ class Gateway(object): chan.setcallback(callback) return chan.id - def _rinfo(self): + def _rinfo(self, update=False): """ return some sys/env information from remote. """ - return RInfo(**self.remote_exec(""" - import sys, os - channel.send(dict( - executable = sys.executable, - version_info = sys.version_info, - curdir = os.getcwd(), - )) - """).receive()) + if update or not hasattr(self, '_cache_rinfo'): + self._cache_rinfo = RInfo(**self.remote_exec(""" + import sys, os + channel.send(dict( + executable = sys.executable, + version_info = sys.version_info, + cwd = os.getcwd(), + )) + """).receive()) + return self._cache_rinfo # _____________________________________________________________________ # diff --git a/py/execnet/testing/test_gateway.py b/py/execnet/testing/test_gateway.py index 70a5fb8a9..20bcc24b6 100644 --- a/py/execnet/testing/test_gateway.py +++ b/py/execnet/testing/test_gateway.py @@ -444,9 +444,22 @@ class BasicRemoteExecution: def test__rinfo(self): rinfo = self.gw._rinfo() assert rinfo.executable - assert rinfo.curdir + assert rinfo.cwd assert rinfo.version_info - + old = self.gw.remote_exec(""" + import os.path + cwd = os.getcwd() + channel.send(os.path.basename(cwd)) + os.chdir('..') + """).receive() + try: + rinfo2 = self.gw._rinfo() + assert rinfo2.cwd == rinfo.cwd + rinfo3 = self.gw._rinfo(update=True) + assert rinfo3.cwd != rinfo2.cwd + finally: + self.gw._cache_rinfo = rinfo + self.gw.remote_exec("import os ; os.chdir(%r)" % old).waitclose() class BasicCmdbasedRemoteExecution(BasicRemoteExecution): def test_cmdattr(self): @@ -487,10 +500,11 @@ def test_channel_endmarker_remote_killterm(): # assert x == 17 class TestPopenGateway(PopenGatewayTestSetup, BasicRemoteExecution): - def test_remote_info_popen(self): + def test_rinfo_popen(self): + #rinfo = py.execnet.PopenGateway()._rinfo() rinfo = self.gw._rinfo() assert rinfo.executable == py.std.sys.executable - assert rinfo.curdir == py.std.os.getcwd() + assert rinfo.cwd == py.std.os.getcwd() assert rinfo.version_info == py.std.sys.version_info def test_chdir_separation(self):