I have parameterized my fixture to call APIs, with different input data to POST request on each call with scope as class
. Since I need to check API response with sent data. I need to read request params of the fixtures into tests.
class Test_create_fixture():
@pytest.fixture(scope="class", params=[0, 1])
def my_fixture(self, request):
"Call incident creation api."
# POST request to API using params value in request data, get data from API
my_data = {'abc': 123, 'severity': 0} # this data is from API
self.data = {'severity': request.param}
return my_data
def test_incident_severity(self, my_fixture, request):
print("self.data", self.data) # 'Test_create_fixture' object has no attribute 'data'
assert my_fixture.get('severity', False) == request.param # AttributeError: 'FixtureRequest' object has no attribute 'param'
But when I run this I am not able to read request params passed to fixture into tests. Also tried to save in instance variable but didn't worked. I have observed that id()
property of self
in fixture and self
in tests is different. Why is so? Is there way to achieve this?