微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

当远程模块具有 pytest_collection_modifyitems() 时,Pytest-xdist 抛出 AssertionError

如何解决当远程模块具有 pytest_collection_modifyitems() 时,Pytest-xdist 抛出 AssertionError

我有一个需要由 xdist 执行的远程脚本,我通过钩子 pytest_xdist_getremotemodule() 提供,我正在执行一些集合更改,这些更改对所有节点都通过 pytest_collection_modifyitems() 执行,但是在 runtestloop 期间worker 因 AssertionError 失败

platform darwin -- Python 3.9.1,pytest-6.2.4,py-1.10.0,pluggy-0.13.1 -- /usr/local/opt/python@3.9/bin/python3.9
cachedir: .pytest_cache
rootdir: /Users/akhileshr/Projects/pytest_test,configfile: pytest.ini
plugins: xdist-2.2.1,easyread-0.1.0,forked-1.3.0
[gw0] darwin Python 3.9.1 cwd: /Users/akhileshr/Projects/pytest_test
[gw1] darwin Python 3.9.1 cwd: /Users/akhileshr/Projects/pytest_test
[gw0] Python 3.9.1 (default,Jan  8 2021,17:17:43)  -- [Clang 12.0.0 (clang-1200.0.32.28)]
[gw1] Python 3.9.1 (default,17:17:43)  -- [Clang 12.0.0 (clang-1200.0.32.28)]
gw0 [6] / gw1 [6]
scheduling tests via LoadScheduling
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR>   File "/usr/local/lib/python3.9/site-packages/_pytest/main.py",line 269,in wrap_session
INTERNALERROR>     session.exitstatus = doit(config,session) or 0
INTERNALERROR>   File "/usr/local/lib/python3.9/site-packages/_pytest/main.py",line 323,in _main
INTERNALERROR>     config.hook.pytest_runtestloop(session=session)
INTERNALERROR>   File "/usr/local/lib/python3.9/site-packages/pluggy/hooks.py",line 286,in __call__
INTERNALERROR>     return self._hookexec(self,self.get_hookimpls(),kwargs)
INTERNALERROR>   File "/usr/local/lib/python3.9/site-packages/pluggy/manager.py",line 93,in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook,methods,line 84,in <lambda>
INTERNALERROR>     self._inner_hookexec = lambda hook,kwargs: hook.multicall(
INTERNALERROR>   File "/usr/local/lib/python3.9/site-packages/pluggy/callers.py",line 208,in _multicall
INTERNALERROR>     return outcome.get_result()
INTERNALERROR>   File "/usr/local/lib/python3.9/site-packages/pluggy/callers.py",line 80,in get_result
INTERNALERROR>     raise ex[1].with_traceback(ex[2])
INTERNALERROR>   File "/usr/local/lib/python3.9/site-packages/pluggy/callers.py",line 187,in _multicall
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>   File "/usr/local/lib/python3.9/site-packages/xdist/dsession.py",line 112,in pytest_runtestloop
INTERNALERROR>     self.loop_once()
INTERNALERROR>   File "/usr/local/lib/python3.9/site-packages/xdist/dsession.py",line 135,in loop_once
INTERNALERROR>     call(**kwargs)
INTERNALERROR>   File "/Users/akhileshr/Projects/pytest_test/pytest_bypass.py",line 62,in worker_workerfinished
INTERNALERROR>     assert not crashitem,(crashitem,node)
INTERNALERROR> AssertionError: ('dum_py.py::test_pytestDum',<WorkerController gw1>)

测试脚本有一个简单的断言语句 1==1

当我从远程脚本中删除 pytest_collection_modifyitems() 函数时,程序运行没有任何问题。有人能帮我理解这个问题的原因吗?

解决方法

您在文件 worker_workerfinished 中似乎有一个名为 /Users/akhileshr/Projects/pytest_test/pytest_bypass.py 的测试/夹具/函数,由于您实施了 pytest_collection_modifyitems(),它正在执行。这就是你的 AssertionError 出现的地方,在第 62 行:assert not crashitem,(crashitem,node)

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。