I have a test and a fixture which I run with pytest:
@pytest.mark.asyncio
@pytest.fixture
async def data_mocker():
data_mocker = Mockdata()
await data_mocker.load()
return data_mocker
@pytest.mark.asyncio
async def test_data_publisher(data_mocker):
for packet in data_mocker.data:
assert packet.published
After the test is run and independenlty of the result, both in test fail and test pass, I want to delete the created mocked data from the disk so I have a data_mocker.cleanup()
which deletes the data created earlier. IT stores the data in a object variable something like:
def cleanup(self):
try:
for packet in self.data:
del packer #Not the actual code. In reality I remove
return True
except:
return False
them from the disk
My question is how do I use my object created by my fixture in my test and THEN after the test is done call the cleanup
method of the object?
Also I want to check that the cleanup was succesfull (it returns a boolean value) and I might want to reuse my fixture in two or more tests before cleanup