Replies: 3 comments 4 replies
-
You could probably use a parametrized fixture instead. |
Beta Was this translation helpful? Give feedback.
-
I got here because of the title, but I think my use case was slightly different. I had a fixture and I wanted to use that to parametrize a test. Something like: @pytest.fixture()
def my_list():
print('get_list function called')
return [1,2,3,4]
@pytest.mark.parametrize("product", my_list)
def test_number(product):
assert type(product) == int But then with my_list in conftest.py. This didn't work, also not variations with In the end, I refactored a bit up, putting all the functionality of the fixture in a function and then using a parametrized fixture, something like: def get_list():
print('get_list function called')
return [1,2,3,4]
@pytest.fixture()
def my_list():
return get_list()
@pytest.fixture(params=get_list())
def product(request):
return request.param
def test_number(product):
assert type(product) == int
def test_other_thing(my_list):
assert len(my_list) == 4 |
Beta Was this translation helpful? Give feedback.
-
Parametrize Happens before fixtures Are available |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
this test case run successfully when i run this test separately but the problem is if i run other test from the same folder then this "get_list" function called every time too.I know this 'get_list' should be mark as fixtures but when i try to send the function name on parametrize then its gives me function objects is not iterable error.
how can i get rid of this?
I want to call this function every time i run other test.
or how to treat this as fixtures to use it in parametrize because the list is dynamic in my real work.
I tried like this too but its failed. The get_list function is not calling other test running but test_number test is not working ,its giving me function objects is not iterable error.
Thank in Advance.
Beta Was this translation helpful? Give feedback.
All reactions