与VBoxManage guestcontrol一起运行时Pytest断管

问题描述

我正在运行一些集成测试,在其中启动Ubuntu 20.04 VM,装入包含测试的共享文件夹并运行它们。这些测试使用pytest运行,涉及对subprocess.run()的一些调用,主要是为了获取systemd服务的journalctl条目。因此,从本质上讲,我启动了虚拟机,并使用VBoxManage guestcontrol来配置虚拟机并运行pytests。

VirtualBox版本:6.1.10
Python版本:3.8.5
pytest版本:6.1.2

defaultdict

如果我从VM内运行测试,则可以正常运行。但是,当使用VBoxManage guestcontrol运行时,出现了brokenPipeError。我在这里粘贴pytest的junit输出

def recent_log_line(service):
  """Searches for a log line with the given URL after a date."""
  after_date = datetime.datetime.Now()
  after_date = after_date.strftime('%Y-%m-%d %H:%M:%s')

  f = subprocess.run(["journalctl","-u",service,'--since',after_date],capture_output=True,encoding='utf-8')
  log = f.stdout
  return 'Succeeded' in log

我尝试使用文件而不是subprocess.PIPE,但效果相同。仅当使用<?xml version="1.0" encoding="utf-8"?><testsuites><testsuite name="pytest" errors="1" failures="0" skipped="0" tests="4" time="30.775" timestamp="2020-10-29T16:53:12.196393" hostname="Ubuntu-test"><testcase classname="test_main" name="test_registration" time="0.001" /><testcase classname="test_main" name="test_healthcheck" time="0.050" /><testcase classname="test_main" name="test_configuration" time="0.039" /><testcase time="0.000" /><testcase classname="pytest" name="internal" time="0.000"><error message="internal error">Traceback (most recent call last): File "/root/.local/lib/python3.8/site-packages/_pytest/main.py",line 257,in wrap_session session.exitstatus = doit(config,session) or 0 File "/root/.local/lib/python3.8/site-packages/_pytest/main.py",line 313,in _main config.hook.pytest_runtestloop(session=session) File "/root/.local/lib/python3.8/site-packages/pluggy/hooks.py",line 286,in __call__ return self._hookexec(self,self.get_hookimpls(),kwargs) File "/root/.local/lib/python3.8/site-packages/pluggy/manager.py",line 93,in _hookexec return self._inner_hookexec(hook,methods,line 84,in &lt;lambda&gt; self._inner_hookexec = lambda hook,kwargs: hook.multicall( File "/root/.local/lib/python3.8/site-packages/pluggy/callers.py",line 208,in _multicall return outcome.get_result() File "/root/.local/lib/python3.8/site-packages/pluggy/callers.py",line 80,in get_result raise ex[1].with_traceback(ex[2]) File "/root/.local/lib/python3.8/site-packages/pluggy/callers.py",line 187,in _multicall res = hook_impl.function(*args) File "/root/.local/lib/python3.8/site-packages/_pytest/main.py",line 338,in pytest_runtestloop item.config.hook.pytest_runtest_protocol(item=item,nextitem=nextitem) File "/root/.local/lib/python3.8/site-packages/pluggy/hooks.py",in _multicall res = hook_impl.function(*args) File "/root/.local/lib/python3.8/site-packages/pytest_rerunfailures.py",line 261,in pytest_runtest_protocol item.ihook.pytest_runtest_logreport(report=report) File "/root/.local/lib/python3.8/site-packages/pluggy/hooks.py",in _multicall res = hook_impl.function(*args) File "/root/.local/lib/python3.8/site-packages/_pytest/terminal.py",line 561,in pytest_runtest_logreport self.flush() File "/root/.local/lib/python3.8/site-packages/_pytest/terminal.py",line 422,in flush self._tw.flush() File "/root/.local/lib/python3.8/site-packages/_pytest/_io/terminalwriter.py",line 174,in flush self._file.flush() brokenPipeError: [Errno 32] broken pipe</error></testcase></testsuite></testsuites> 运行时才会出现此问题。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)