How to use variable from fixture as a parameter in @pytest.mark.parametrize()?

546 Views Asked by At

I hope that there is a simple solution for this, but I was unable to find anything. Basically, i have fixtures.py file where I have created a simple fixture that returns some variable:

import pytest

@pytest.fixture
def fix_test():
   value = "some_value"
   return value

Now, I know that this does not work, but just so you can get a clear picture on this:

import pytest

from fixtures import test_fixture

@pytest.mark.parametrize("first_param","second_param",[
   (test_fixture, "other_value"),
   ("other_value", test_fixture)
])
def test_fixtures(first_param, second_param)
   print(first_param, second param)

So, my question remains, how to use variable from fixture as a parameter in @pytest.mark.parametrize()?

I tried with every option that came to my mind: To run fixtures independently, to run them in other file and import values in test directly (overkill, I know)... Closest I got is with something like this:

import pytest

from fixtures import test_fixture

@pytest.mark.parametrize("test_fixture", ["test_fixture"], indirect=True)
def test_2(test_fixture):
    print(test_fixture)

but the problem here is that I don't know how to add another parameter apart from this one.

0

There are 0 best solutions below