簡體   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