0

我有带有环境的 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 上使用 x-dist 插件在 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, 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 主机的响应带有一些意想不到的东西,但我无法理解是什么问题。有谁能够帮助我?

4

1 回答 1

0

问题出在远程 Windows 主机上。没有系统的python解释器路径(在环境变量路径中)(只有用户)。我在 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 中,而是在无法执行代码的远程主机中。这样我开始检查系统变量

于 2020-12-05T05:42:47.530 回答