当尝试使用ssh在远程Windows主机上运行测试时,pytest x-dist INTERNALERROR

问题描述

我的Ubuntu主机具有以下环境: Python 3.6.9,pytest-4.6.9,execnet 1.7.1,x-dist 1.31.0

和Windows主机:Windows版本10.0.19041.508,python 3.7.5,pytest 5.4.1,execnet 1.7.1

我想使用x-dist插件在Ubuntu的Windows主机上运行测试: pytest -v -d --tx ssh=admin@10.15.20.15 --rsyncdir / etc / ansible / autotests / release C:\ users \ Public \ test_create_session.py

我收到错误消息:

    ============================= test session starts =============================
platform linux -- Python 3.6.9,pytest-4.6.9,py-1.8.1,pluggy-0.13.1 -- /usr/bin/python
cachedir: .pytest_cache
rootdir: /etc/ansible/autotests/release
plugins: teamcity-messages-1.27,xdist-1.31.0,forked-1.1.3
gw0 I�� 㤠���� �믮����� 㪠������ �ணࠬ��.
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR>   File "/usr/local/lib/python3.6/dist-packages/_pytest/main.py",line 204,in wrap_session
INTERNALERROR>     config.hook.pytest_sessionstart(session=session)
INTERNALERROR>   File "/home/test/.local/lib/python3.6/site-packages/pluggy/hooks.py",line 286,in __call__
INTERNALERROR>     return self._hookexec(self,self.get_hookimpls(),kwargs)
INTERNALERROR>   File "/home/test/.local/lib/python3.6/site-packages/pluggy/manager.py",line 93,in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook,methods,line 87,in <lambda>
INTERNALERROR>     firstresult=hook.spec.opts.get("firstresult") if hook.spec else False,INTERNALERROR>   File "/home/test/.local/lib/python3.6/site-packages/pluggy/callers.py",line 208,in _multicall
INTERNALERROR>     return outcome.get_result()
INTERNALERROR>   File "/home/test/.local/lib/python3.6/site-packages/pluggy/callers.py",line 80,in get_result
INTERNALERROR>     raise ex[1].with_traceback(ex[2])
INTERNALERROR>   File "/home/test/.local/lib/python3.6/site-packages/pluggy/callers.py",line 187,in _multicall
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>   File "/usr/local/lib/python3.6/dist-packages/xdist/dsession.py",line 78,in pytest_sessionstart
INTERNALERROR>     nodes = self.nodemanager.setup_nodes(putevent=self.queue.put)
INTERNALERROR>   File "/usr/local/lib/python3.6/dist-packages/xdist/workermanage.py",line 64,in setup_nodes
INTERNALERROR>     nodes.append(self.setup_node(spec,putevent))
INTERNALERROR>   File "/usr/local/lib/python3.6/dist-packages/xdist/workermanage.py",line 68,in setup_node
INTERNALERROR>     gw = self.group.makegateway(spec)
INTERNALERROR>   File "/usr/local/lib/python3.6/dist-packages/execnet/multi.py",line 111,in makegateway
INTERNALERROR>     """)
INTERNALERROR>   File "/usr/local/lib/python3.6/dist-packages/execnet/gateway.py",line 119,in remote_exec
INTERNALERROR>     gateway_base.dumps_internal((source,call_name,kwargs)))
INTERNALERROR>   File "/usr/local/lib/python3.6/dist-packages/execnet/gateway_base.py",line 710,in _send
INTERNALERROR>     message.to_io(self._io)
INTERNALERROR>   File "/usr/local/lib/python3.6/dist-packages/execnet/gateway_base.py",line 130,in to_io
INTERNALERROR>     io.write(header+self.data)
INTERNALERROR>   File "/usr/local/lib/python3.6/dist-packages/execnet/gateway_base.py",line 101,in write
INTERNALERROR>     self.outfile.flush()
INTERNALERROR> brokenPipeError: [Errno 32] broken pipe

当我在其他Windows主机上运行相同的测试时,所有工作正常,没有错误。我认为此Windows主机响应有一些意外情况,但我无法理解是什么问题。有人可以帮我吗?

解决方法

问题出在远程Windows主机上。系统(只有用户)没有指向python解释器的路径(在环境变量Path中)。我在System的Path环境变量中向Python和Pytest添加了路径,并且它起作用了!

我如何定位的:

我制作了一个简单的脚本来检查execnet(远程代码执行)是否起作用:

import execnet,os
gw = execnet.makegateway(ssh="admin@10.15.20.15")
channel = gw.remote_exec("""
import sys,os
channel.send((sys.platform,tuple(sys.version_info),os.getpid()))
""")
platform,version_info,remote_pid = channel.receive()
print(f"Platform: {platform},Version Info: {version_info},Remote Pid: {remote_pid}")

此脚本不起作用,我意识到问题不在pytest中,而是在无法执行代码的远程主机中。这样,我开始检查系统变量