I want to do call pytest fixtures on a normal function (not a test function). For example:
Below code is sitting inside conftest.py
DATA_PATH_TEMP = '/data/data_temp.yaml'
@pytest.fixture()
def datapath():
return DATA_PATH_TEMP
I have my test function on a test file:
@pytest.fixture()
def data_metadata(datapath):
return datapath + '.yaml'
def cleanup_data(*args):
for arg in args:
if os.path.exists(arg):
os.remove(arg)
def test_data_tmp(datapath):
xxxxx
cleanup_data(datapath, data_metadata)
I tried this code and it didn't work and threw me an error that datapath
fixture is not recognized. I also wonder if it is possible to save that fixture as a global variable, so that I can make something like this:
DATAPATH = ... # the return of the fixture
def cleanup_data():
if os.path.exists(DATAPATH):
os.remove(DATAPATH)
Thanks!
question from:
https://stackoverflow.com/questions/65883737/pytest-fixtures-not-found-when-called-inside-a-non-test-function 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…