属性错误:';配置';对象没有属性';测试系统&x27; rootdir:python,ini文件:pytest.ini,testpath:test\u案例 插件:metadata-1.8.0、html-1.22.0、sugar-0.9.2、timeout-1.3.3、forked-1.0.2、xdist-1.29.0、repeat-0.8.0 超时:3600.0s 超时方法:信号 仅超时函数:False gw0正常/gw1正常/gw2正常 ../python-venv/lib/python2.7/site-packages/pluggy/hooks.py:289:in\uu调用__ 返回self._hookexec(self,self.get_hookimpls(),kwargs) ../python-venv/lib/python2.7/site-packages/pluggy/manager.py:87:in\uhookexec 返回self.\u inner\u hookexec(钩子、方法、kwargs) ../python-venv/lib/python2.7/site-packages/pluggy/manager.py:81:in firstresult=hook.spec.opts.get(“firstresult”),如果hook.spec else为False, ../python-venv/lib/python2.7/site-packages/\u-pytest/python.py:234:in-pytest\u-pycollect\u-makeitem res=列表(收集器类型函数(名称,obj)) ../python-venv/lib/python2.7/site-packages/\u-pytest/python.py:410:in\u-genfunctions self.ihook.pytest\u generate\u测试(metafunc=metafunc) ../python-venv/lib/python2.7/site-packages/pluggy/hooks.py:289:in\uu调用__ 返回self._hookexec(self,self.get_hookimpls(),kwargs) ../python-venv/lib/python2.7/site-packages/pluggy/manager.py:87:in\uhookexec 返回self.\u inner\u hookexec(钩子、方法、kwargs) ../python-venv/lib/python2.7/site-packages/pluggy/manager.py:81:in firstresult=hook.spec.opts.get(“firstresult”),如果hook.spec else为False, ../../modules/test/python/test\u cases/uts\u plugin.py:20:in-pytest\u generate\u tests 对于metafunc.config.test\u system.build\u configuration.get中的build\u config( E AttributeError:'Config'对象没有属性'test\u system' gw0[1]/gw1正常/gw2正常
所有测试运行正常,无需使用“-n”选项。我打印了config的属性,其中确实有test_系统,我不知道它为什么会失败。在使用属性错误:';配置';对象没有属性';测试系统&x27; rootdir:python,ini文件:pytest.ini,testpath:test\u案例 插件:metadata-1.8.0、html-1.22.0、sugar-0.9.2、timeout-1.3.3、forked-1.0.2、xdist-1.29.0、repeat-0.8.0 超时:3600.0s 超时方法:信号 仅超时函数:False gw0正常/gw1正常/gw2正常 ../python-venv/lib/python2.7/site-packages/pluggy/hooks.py:289:in\uu调用__ 返回self._hookexec(self,self.get_hookimpls(),kwargs) ../python-venv/lib/python2.7/site-packages/pluggy/manager.py:87:in\uhookexec 返回self.\u inner\u hookexec(钩子、方法、kwargs) ../python-venv/lib/python2.7/site-packages/pluggy/manager.py:81:in firstresult=hook.spec.opts.get(“firstresult”),如果hook.spec else为False, ../python-venv/lib/python2.7/site-packages/\u-pytest/python.py:234:in-pytest\u-pycollect\u-makeitem res=列表(收集器类型函数(名称,obj)) ../python-venv/lib/python2.7/site-packages/\u-pytest/python.py:410:in\u-genfunctions self.ihook.pytest\u generate\u测试(metafunc=metafunc) ../python-venv/lib/python2.7/site-packages/pluggy/hooks.py:289:in\uu调用__ 返回self._hookexec(self,self.get_hookimpls(),kwargs) ../python-venv/lib/python2.7/site-packages/pluggy/manager.py:87:in\uhookexec 返回self.\u inner\u hookexec(钩子、方法、kwargs) ../python-venv/lib/python2.7/site-packages/pluggy/manager.py:81:in firstresult=hook.spec.opts.get(“firstresult”),如果hook.spec else为False, ../../modules/test/python/test\u cases/uts\u plugin.py:20:in-pytest\u generate\u tests 对于metafunc.config.test\u system.build\u configuration.get中的build\u config( E AttributeError:'Config'对象没有属性'test\u system' gw0[1]/gw1正常/gw2正常,python,pytest,xdist,Python,Pytest,Xdist,所有测试运行正常,无需使用“-n”选项。我打印了config的属性,其中确实有test_系统,我不知道它为什么会失败。在使用xdist分发测试时,在主节点和工作节点之间共享数据的常用方法是实现pytest_configure_节点钩子,然后访问下面的数据方式: rootdir: python, inifile: pytest.ini, testpaths: test_cases plugins: metadata-1.8.0, html-1.22.0, sugar-0.9.2, timeout-
xdist
分发测试时,在主节点和工作节点之间共享数据的常用方法是实现pytest_configure_节点
钩子,然后访问下面的数据方式:
rootdir: python, inifile: pytest.ini, testpaths: test_cases
plugins: metadata-1.8.0, html-1.22.0, sugar-0.9.2, timeout-1.3.3, forked-1.0.2, xdist-1.29.0, repeat-0.8.0
timeout: 3600.0s
timeout method: signal
timeout func_only: False
gw0 ok / gw1 ok / gw2 ok
../python-venv/lib/python2.7/site-packages/pluggy/hooks.py:289: in __call__
return self._hookexec(self, self.get_hookimpls(), kwargs)
../python-venv/lib/python2.7/site-packages/pluggy/manager.py:87: in _hookexec
return self._inner_hookexec(hook, methods, kwargs)
../python-venv/lib/python2.7/site-packages/pluggy/manager.py:81: in <lambda>
firstresult=hook.spec.opts.get("firstresult") if hook.spec else False,
../python-venv/lib/python2.7/site-packages/_pytest/python.py:234: in pytest_pycollect_makeitem
res = list(collector._genfunctions(name, obj))
../python-venv/lib/python2.7/site-packages/_pytest/python.py:410: in _genfunctions
self.ihook.pytest_generate_tests(metafunc=metafunc)
../python-venv/lib/python2.7/site-packages/pluggy/hooks.py:289: in __call__
return self._hookexec(self, self.get_hookimpls(), kwargs)
../python-venv/lib/python2.7/site-packages/pluggy/manager.py:87: in _hookexec
return self._inner_hookexec(hook, methods, kwargs)
../python-venv/lib/python2.7/site-packages/pluggy/manager.py:81: in <lambda>
firstresult=hook.spec.opts.get("firstresult") if hook.spec else False,
../../modules/test/python/test_cases/uts_plugin.py:20: in pytest_generate_tests
for build_config in metafunc.config.test_system.build_configuration.get(
E AttributeError: 'Config' object has no attribute 'test_system'
gw0 [1] / gw1 ok / gw2 ok
下面是一个我试图与您发布的异常回溯联系在一起的示例:
if hasattr(request.config, 'slaveinput'):
... # we are in worker node
else:
... # we are in master
请注意,您不能在主程序和辅助程序之间共享TestSystem
实例,只能共享基本数据类型(字符串、数字、列表、dict等)。这就是为什么只有build\u配置
dict存储在slaveinput
中,并且每个辅助程序都从共享数据重新创建自己的TestSystem
对象的原因
示例测试:
class TestSystem:
def __init__(self):
self.build_configuration = dict()
def pytest_configure(config):
if hasattr(config, 'slaveinput'): # slave
return
# we are on master node
# create test system object, attach to config
s = TestSystem()
s.build_configuration['foo'] = 'bar'
config.test_system = s
def pytest_configure_node(node):
# this is the pendant of pytest_configure hook, but for worker nodes only
# store serializable stuff from test system object in slaveinput
node.slaveinput['test_system_serialized'] = node.config.test_system.build_configuration
def pytest_generate_tests(metafunc):
if hasattr(metafunc.config, 'slaveinput'): # we are in worker node
# restore test system object using serialized data
s = TestSystem()
s.build_configuration = metafunc.config.slaveinput['test_system_serialized']
else: # master
# simply get test system instance from config
s = metafunc.config.test_system
# generate tests
if 'test_system' in metafunc.fixturenames:
metafunc.parametrize('test_system', [s])
连续运行测试会产生:
import time
import pytest
@pytest.mark.parametrize('n', range(1, 5))
def test_eggs(n, test_system):
time.sleep(1)
assert test_system.build_configuration['foo'] == 'bar'
在分布式模式下运行测试:
$ pytest -v
...
test_spam.py::test_eggs[test_system0-1] PASSED
test_spam.py::test_eggs[test_system0-2] PASSED
test_spam.py::test_eggs[test_system0-3] PASSED
test_spam.py::test_eggs[test_system0-4] PASSED
配置中的
test\u system
是什么?是您自己存储的吗?配置中没有参数,因为会话在xdist
中的不同测试进程之间不共享。您必须在不同节点之间复制数据。如果您提供有关测试代码的更多信息,我可以提供一个如何执行此操作的工作示例。th如果你@hoefling,我会试试看,然后告诉你
$ pytest -v -n4
...
scheduling tests via LoadScheduling
test_spam.py::test_eggs[test_system0-1]
test_spam.py::test_eggs[test_system0-2]
test_spam.py::test_eggs[test_system0-4]
test_spam.py::test_eggs[test_system0-3]
[gw1] [ 25%] PASSED test_spam.py::test_eggs[test_system0-2]
[gw2] [ 50%] PASSED test_spam.py::test_eggs[test_system0-3]
[gw0] [ 75%] PASSED test_spam.py::test_eggs[test_system0-1]
[gw3] [100%] PASSED test_spam.py::test_eggs[test_system0-4]