Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x Pytest使用VBoxManage guestcontrol运行时损坏的管道_Python 3.x_Subprocess_Pytest_Virtualbox_Virtualbox Guest Additions - Fatal编程技术网

Python 3.x Pytest使用VBoxManage guestcontrol运行时损坏的管道

Python 3.x Pytest使用VBoxManage guestcontrol运行时损坏的管道,python-3.x,subprocess,pytest,virtualbox,virtualbox-guest-additions,Python 3.x,Subprocess,Pytest,Virtualbox,Virtualbox Guest Additions,我正在运行一些集成测试,其中我启动了一个Ubuntu 20.04虚拟机,装载一个包含测试的共享文件夹并运行它们。这些测试使用pytest运行,并涉及对subprocess.run()的一些调用,主要是为了获取systemd服务的journalctl条目。因此,本质上,我启动VM并使用VBoxManage guestcontrol来配置VM并运行pytests Virtualbox版本:6.1.10 Python版本:3.8.5 pytest版本:6.1.2 def recent_log_line

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

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

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
如果我在虚拟机中运行测试,它工作得很好。但是,当使用VBoxManage guestcontrol运行时,会出现断管错误。我在这里粘贴pytest的junit输出

<?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, kwargs)
  File "/root/.local/lib/python3.8/site-packages/pluggy/manager.py", line 84, in &lt;lambda&gt;
    self._inner_hookexec = lambda hook, methods, 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", 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, kwargs)
  File "/root/.local/lib/python3.8/site-packages/pluggy/manager.py", line 84, in &lt;lambda&gt;
    self._inner_hookexec = lambda hook, methods, 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_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", 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, kwargs)
  File "/root/.local/lib/python3.8/site-packages/pluggy/manager.py", line 84, in &lt;lambda&gt;
    self._inner_hookexec = lambda hook, methods, 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/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>
回溯(最近一次呼叫最后一次):
文件“/root/.local/lib/python3.8/site packages/\u pytest/main.py”,第257行,在wrap\u会话中
session.exitstatus=doit(配置,会话)或0
文件“/root/.local/lib/python3.8/site packages/_-pytest/main.py”,第313行,在_-main中
config.hook.pytest\u runtestloop(session=session)
文件“/root/.local/lib/python3.8/site packages/pluggy/hooks.py”,第286行,在调用中__
返回self._hookexec(self,self.get_hookimpls(),kwargs)
文件“/root/.local/lib/python3.8/site packages/pluggy/manager.py”,第93行,在
返回self.\u inner\u hookexec(钩子、方法、kwargs)
文件“/root/.local/lib/python3.8/site packages/pluggy/manager.py”,第84行,lambda格式
self._inner_hookexec=lambda hook,methods,kwargs:hook.multicall(
文件“/root/.local/lib/python3.8/site packages/pluggy/callers.py”,第208行,在multicall中
返回结果。获取结果()
文件“/root/.local/lib/python3.8/site packages/pluggy/callers.py”,第80行,在get_结果中
raise ex[1]。使用_回溯(ex[2])
文件“/root/.local/lib/python3.8/site packages/pluggy/callers.py”,第187行,在_multicall中
res=钩子函数(*args)
文件“/root/.local/lib/python3.8/site packages/\u pytest/main.py”,第338行,在pytest\u runtestloop中
item.config.hook.pytest\u runtest\u协议(item=item,nextitem=nextitem)
文件“/root/.local/lib/python3.8/site packages/pluggy/hooks.py”,第286行,在调用中__
返回self._hookexec(self,self.get_hookimpls(),kwargs)
文件“/root/.local/lib/python3.8/site packages/pluggy/manager.py”,第93行,在
返回self.\u inner\u hookexec(钩子、方法、kwargs)
文件“/root/.local/lib/python3.8/site packages/pluggy/manager.py”,第84行,lambda格式
self._inner_hookexec=lambda hook,methods,kwargs:hook.multicall(
文件“/root/.local/lib/python3.8/site packages/pluggy/callers.py”,第208行,在multicall中
返回结果。获取结果()
文件“/root/.local/lib/python3.8/site packages/pluggy/callers.py”,第80行,在get_结果中
raise ex[1]。使用_回溯(ex[2])
文件“/root/.local/lib/python3.8/site packages/pluggy/callers.py”,第187行,在_multicall中
res=钩子函数(*args)
pytest\u runtest\u协议第261行的文件“/root/.local/lib/python3.8/site packages/pytest\u rerruntilures.py”
item.ihook.pytest\u runtest\u日志报告(报告=报告)
文件“/root/.local/lib/python3.8/site packages/pluggy/hooks.py”,第286行,在调用中__
返回self._hookexec(self,self.get_hookimpls(),kwargs)
文件“/root/.local/lib/python3.8/site packages/pluggy/manager.py”,第93行,在
返回self.\u inner\u hookexec(钩子、方法、kwargs)
文件“/root/.local/lib/python3.8/site packages/pluggy/manager.py”,第84行,lambda格式
self._inner_hookexec=lambda hook,methods,kwargs:hook.multicall(
文件“/root/.local/lib/python3.8/site packages/pluggy/callers.py”,第208行,在multicall中
返回结果。获取结果()
文件“/root/.local/lib/python3.8/site packages/pluggy/callers.py”,第80行,在get_结果中
raise ex[1]。使用_回溯(ex[2])
文件“/root/.local/lib/python3.8/site packages/pluggy/callers.py”,第187行,在_multicall中
res=钩子函数(*args)
文件“/root/.local/lib/python3.8/site packages/\u pytest/terminal.py”,第561行,在pytest\u runtest\u日志报告中
self.flush()
文件“/root/.local/lib/python3.8/site packages/_pytest/terminal.py”,第422行,刷新
self._tw.flush()
文件“/root/.local/lib/python3.8/site packages/\u pytest/\u io/terminalwriter.py”,第174行,刷新
self.\u file.flush()
断管错误:[Errno 32]断管
我尝试使用文件而不是subprocess.PIPE,但效果相同。只有在使用
VBoxManage guestcontrol
运行时才会出现问题