I'm using pytest
to do testing on splitting data into train, val, test set for machine learning problem. I create temporary files using tmpdir_factory
, but it threw me an error something like TypeError: Expected binary or unicode string, got local('/tmp/pytest/pytest-4/test_folder0/train.tfrecord')
. Here is my code:
Inside conftest.py
:
DATA_FOLDER = 'test_folder'
@pytest.fixture(scope="session")
def train_dataset(tmpdir_factory):
return tmpdir_factory.mktemp(DATA_FOLDER).join('train.tfrecord')
@pytest.fixture(scope="session")
def val_dataset(tmpdir_factory):
return tmpdir_factory.mktemp(DATA_FOLDER).join('val.tfrecord')
@pytest.fixture(scope="session")
def test_dataset(tmpdir_factory):
return tmpdir_factory.mktemp(DATA_FOLDER).join('test.tfrecord')
Inside the test file:
def test_split(train_dataset, val_dataset, test_dataset):
# the arguments of split_function refer to the path where the splitting results is written
split_function(train_dataset, val_dataset, test_dataset)
"""continue with assert functions"""
Can anyone please help? Thanks
question from:
https://stackoverflow.com/questions/65891049/pytest-tmpdir-factory-threw-an-error-expected-binary-or-unicode-string-got-loc 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…