Pytest x-dist INTERNALERROR 尝试使用 ssh 在远程 Windows 主机上进行 运行 测试

Pytest x-dist INTERNALERROR when trying to run tests on remote Windows host using ssh

我有 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

我想在 Ubuntu 的 Windows 主机上 运行 测试,使用 x-dist 插件: 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, kwargs)
INTERNALERROR>   File "/home/test/.local/lib/python3.6/site-packages/pluggy/manager.py", 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 中)的路径(仅供用户使用)。我在系统的 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,而是在远程主机,无法执行代码。这样我就开始检查系统变量