繁体   English   中英

如何更改 pytest-bdd 中下一步的变量?

[英]How can I change variables for the next step in pytest-bdd?

我想将 x 从一个步骤更改为另一个步骤,而不添加另一个函数

Feature: Calculator
    Scenario Outline: simple sum
        Given the x is 1
        And the x is <x>

    Examples:
        | x |
        | 5 |
from pytest_bdd import given, when, then, scenario, parsers
import logging
info = logging.getLogger('test').info

@scenario("test.feature", "simple sum")
def test_outlined():
    pass

@given(parsers.parse("the x is {x}"))
@given("the x is <x>")
def f(request, x):
    info("x=%s" % x)

输出:

2021-08-31 14:23:30 INFO x=1
2021-08-31 14:23:30 INFO x=1

想要的输出:

2021-08-31 14:23:30 INFO x=1
2021-08-31 14:23:30 INFO x=5

非常感谢,请帮忙

只要有可能,您就可以使用场景大纲表

你必须在你的功能文件中这样写

Feature: Calculator
Scenario: simple sum
    Given the x is <x1>
    And the x is <x2>
    And the x is <x3>

Examples:
  | x1 | x2 | x3 |
  | 1  | 5  | 9  |

并在您的步骤定义文件中

@given(parsers.parse("the x is {x}"))
def compute(request, x):
    info("x=%s" % x)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM