1

我正在使用 pytest-6.2.4 通过插件 allure-pytest-bdd-2.8.36、bdd-4.0.2 进行测试自动化。Python 版本是 3.6.9。

使用标志 --alluredir=reports 运行 pytest 时发生 KeyError。测试包含带有示例的功能:

| empty_answer1    | <- variable name
| ---------------- |
| {"playlists":[]} | <- variable value
| {"playlists":[]} | <- variable value

据我所知,控制台输出显示错误发生在格式化过程中:

    @pytest.mark.usefixtures(*function_args)
    def scenario_wrapper(request):
>       _execute_scenario(feature, scenario, request, encoding)

/home/yuliya/.local/lib/python3.6/site-packages/pytest_bdd/scenario.py:177: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/home/yuliya/.local/lib/python3.6/site-packages/pytest_bdd/scenario.py:143: in _execute_scenario
    _execute_step_function(request, scenario, step, step_func)
/home/yuliya/.local/lib/python3.6/site-packages/pytest_bdd/scenario.py:110: in _execute_step_function
    request.config.hook.pytest_bdd_before_step_call(**kw)
/home/yuliya/.local/lib/python3.6/site-packages/pluggy/hooks.py:286: in __call__
    return self._hookexec(self, self.get_hookimpls(), kwargs)
/home/yuliya/.local/lib/python3.6/site-packages/pluggy/manager.py:93: in _hookexec
    return self._inner_hookexec(hook, methods, kwargs)
/home/yuliya/.local/lib/python3.6/site-packages/pluggy/manager.py:87: in <lambda>
    firstresult=hook.spec.opts.get("firstresult") if hook.spec else False,
/home/yuliya/.local/lib/python3.6/site-packages/allure_pytest_bdd/pytest_bdd_listener.py:65: in pytest_bdd_before_step_call
    step_result.name = get_step_name(request.node, step)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

node = <Function test_creating_playlists__responding_to_requests[AUTOTEST-9973991-00 -  0 (9973991\u0410)-\u0421\u0430\u043b\..._number=9973991&route_dir=0&route_type=\u0410&device_type=1&trip_short_name=00&boardNumber=773410446-{"playlists":[]}]>
step = <pytest_bdd.parser.Step object at 0x7f5db6a55198>

    def get_step_name(node, step):
        name = "{step_keyword} {step_name}".format(step_keyword=step.keyword, step_name=step.name)
        if hasattr(node, 'callspec'):
            for key, value in node.callspec.params.items():
                name = name.replace("<{key}>".format(key=key), "<{{{key}}}>".format(key=key))
>               name = name.format(**node.callspec.params)
E               KeyError: '"playlists"'

/home/yuliya/.local/lib/python3.6/site-packages/allure_pytest_bdd/utils.py:15: KeyError

示例类型已通过 example_converters 在 python 脚本中显式声明,如下所示:

scenarios('../features/requestroutePL.feature', example_converters=dict(locality=str,
                                                                        route=str,
                                                                        trip=str,
                                                                        mmetype=str,
                                                                        statusPL=str,
                                                                        urlwithroute=str,
                                                                        urlwithroute2=str,
                                                                        empty_answer1=str,
                                                                        urlwithroute3=str,
                                                                        empty_answer2=str))

我试图用 ''、'%' 符号转义大括号,并使大括号加倍。那一切都是徒劳的。请帮我解决这个问题。我已经没有想法了。

唯一使测试通过的事情是从示例中完全删除大括号。但这个可疑的步骤似乎不是答案。最重要的是,这种行为是不一致的,bcs 在另一个测试中的相同构造没有引发任何错误。

非常感谢任何帮助。

4

0 回答 0