0

I am trying to use parameterized fixture in my pytest-bdd framework. Normal fixture works fine. But If I am passing parameters, it gives below error The requested fixture has no parameter defined for test:

Below is my code(Sample). Waht is the correct usage here?

@pytest.fixture(params=[1,2])
def ba_data(request):
    print("this is fixture")
    return request.param


@given(parsers.cfparse('Collect testdata'))
def required_data(ba_data):
    print(ba_data)

S_G
  • 67
  • 6

2 Answers2

0

it also does not work for fixture generated by pytest_generate_tests defined inside conftest.py

def pytest_generate_tests(metafunc):
   if "numberinput" in metafunc.fixturenames:
      metafunc.parametrize("numberinput", [1, 2, 3])

guess pytest-bdd did not support fixture properly

diamdiam
  • 16
  • 1
0

in order to use parameterized fixture in pytest-bdd you have to declare the scenario using @scenario("yourfeaturename.feature","your scenario name")

it would not work if you use the scenarios function as

scenarios("yourfeaturename.feature")

you will have to pass the fixture to the function below @scenario

@scenario("yourfeaturename.feature","your scenario name")
def test_mytest(ba_data):    
   pass


@pytest.fixture(params=[1,2])
def ba_data(request):
   print("this is fixture")
   return request.param


@given(parsers.cfparse('Collect testdata'))
def required_data(ba_data):
   print(ba_data)
Bihag Kashikar
  • 1,009
  • 1
  • 2
  • 13
diamdiam
  • 16
  • 1
  • Thank you so much. It worked ! But is there a way to avoid hard coding scenari name? in this case. – S_G Jun 30 '23 at 08:18