1

I want to change the x from one step to the other, without adding another function

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)

output:

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

wanted output:

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

thank you so much, please help

  • You can use scenario outline tables whenever it is possible. See [this](http://www.datio.com/bbdd/behavior-driver-development-with-python-a-humble-introduction/). – HamzaFarooq Oct 20 '21 at 07:49

1 Answers1

1

You have to write like this in your feature file

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

and in your step definition file

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)
HamzaFarooq
  • 429
  • 1
  • 4
  • 16
  • 1
    thank you for your answer, but in that way the output is: 2021-10-21 09:23:38 INFO x= 2021-10-21 09:23:38 INFO x= 2021-10-21 09:23:38 INFO x= I want something more: 2021-10-21 09:23:38 INFO x=1 2021-10-21 09:23:38 INFO x=5 2021-10-21 09:23:38 INFO x=9 – goncalo andrade Oct 21 '21 at 08:25
  • 1
    @goncaloandrade I have updated the answer. Please check it – HamzaFarooq Oct 21 '21 at 12:04