1

我想将 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

非常感谢,请帮忙

4

1 回答 1

1

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

Feature: Calculator
Scenario Outline: simple sum
    Given the x is 1
    And the x is 5
    And the x is 9

并在您的步骤定义文件中

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}"))
def f(request, x):
    info("x=%s" % x)
于 2021-10-20T07:34:53.207 回答