当远程模块具有Pytest_collection_modifyitems()时,Pytest xdist抛出断言错误



我有一个需要由xdist执行的远程脚本,我通过钩子pytest_xdist_getremotemmodule((提供该脚本,我正在通过pytest_collection_modifyitems((执行一些集合更改,这些更改对所有节点都是通用的,但在运行测试循环期间,工作程序失败,出现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, Jan  8 2021, 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, kwargs)
INTERNALERROR>   File "/usr/local/lib/python3.9/site-packages/pluggy/manager.py", line 84, in <lambda>
INTERNALERROR>     self._inner_hookexec = lambda hook, methods, 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((函数时,程序可以正常工作。有人能帮我理解这个问题的原因吗?

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

最新更新