pytest xdist在使用多进程执行测试用例时崩溃

2024-06-16 09:16:09 发布

您现在位置:Python中文网/ 问答频道 /正文

没有pytest-xdist-n参数,测试运行正常

但是,当我使用多个进程执行它时,即-n 10,它会由于以下回溯而失败

INTERNALERROR> Traceback (most recent call last):
INTERNALERROR>   File "c:\jay\work\automation\pytest-splunk-addon\new_dev_environment\pyparallel\lib\site-packages\_pytest\main.py", line 191, in wrap_session
INTERNALERROR>     session.exitstatus = doit(config, session) or 0
INTERNALERROR>   File "c:\jay\work\automation\pytest-splunk-addon\new_dev_environment\pyparallel\lib\site-packages\_pytest\main.py", line 247, in _main
INTERNALERROR>     config.hook.pytest_runtestloop(session=session)
INTERNALERROR>   File "c:\jay\work\automation\pytest-splunk-addon\new_dev_environment\pyparallel\lib\site-packages\pluggy\hooks.py", line 286, in __call__
INTERNALERROR>     return self._hookexec(self, self.get_hookimpls(), kwargs)
INTERNALERROR>   File "c:\jay\work\automation\pytest-splunk-addon\new_dev_environment\pyparallel\lib\site-packages\pluggy\manager.py", line 93, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR>   File "c:\jay\work\automation\pytest-splunk-addon\new_dev_environment\pyparallel\lib\site-packages\pluggy\manager.py", line 87, in <lambda>
INTERNALERROR>     firstresult=hook.spec.opts.get("firstresult") if hook.spec else False,
INTERNALERROR>   File "c:\jay\work\automation\pytest-splunk-addon\new_dev_environment\pyparallel\lib\site-packages\pluggy\callers.py", line 208, in _multicall
INTERNALERROR>     return outcome.get_result()
INTERNALERROR>   File "c:\jay\work\automation\pytest-splunk-addon\new_dev_environment\pyparallel\lib\site-packages\pluggy\callers.py", line 80, in get_result
INTERNALERROR>     raise ex[1].with_traceback(ex[2])
INTERNALERROR>   File "c:\jay\work\automation\pytest-splunk-addon\new_dev_environment\pyparallel\lib\site-packages\pluggy\callers.py", line 187, in _multicall
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>   File "c:\jay\work\automation\pytest-splunk-addon\new_dev_environment\pyparallel\lib\site-packages\xdist\dsession.py", line 112, in pytest_runtestloop
INTERNALERROR>     self.loop_once()
INTERNALERROR>   File "c:\jay\work\automation\pytest-splunk-addon\new_dev_environment\pyparallel\lib\site-packages\xdist\dsession.py", line 135, in loop_once
INTERNALERROR>     call(**kwargs)
INTERNALERROR>   File "c:\jay\work\automation\pytest-splunk-addon\new_dev_environment\pyparallel\lib\site-packages\xdist\dsession.py", line 177, in worker_workerfinished
INTERNALERROR>     assert not crashitem, (crashitem, node)
INTERNALERROR> AssertionError: ('tests/test_my_addon.py::Test_App::test_props_fields_positive[splunkd::field::extractthree]', <WorkerController gw7>)

我知道解决方案可能非常特定于我的实现。但我只想知道它出错的可能原因是什么。我尝试在测试用例中查找共享对象/依赖项,但找不到

这一错误的可能原因是什么?在当前的实现中有哪些高级别的步骤需要了解

编辑

针对我的情况,我缩小了问题的范围。在我当前的实现中,我使用一个类来表示一个对象。它没有任何方法或任何东西。我创建这个类只是为了使它成为每个正在执行的测试用例的标准

class Field(object):
    """
        Contains the field properties

        Args:
            field_json (dict): dictionary containing field properties 
    """

    def __init__(self, field_json=None):
        self.name = field_json.get("name")
        self.field_type = field_json.get("field_type")
        self.expected_values = field_json.get("expected_values", ["*"])
        self.negative_values = field_json.get("negative_values", ["-", ""])
        self.condition = field_json.get("condition", ["-", ""])
        self.validity = field_json.get("validity", "")

    def __str__(self):
        return self.name

我的测试用例用字段列表参数化。问题似乎在于它。当我移除这个类并使用字典时,测试开始正常工作


Tags: pyaddondevselffieldnewenvironmentpytest