Python 3.x Pytest正在创建要读取的临时CSV文件

Python 3.x Pytest正在创建要读取的临时CSV文件,python-3.x,csv,pytest,Python 3.x,Csv,Pytest,我有一些代码根据传入的id号解析csv中的某些值。为了进行测试,我想使用pytest为CSV创建虚拟数据文件 @pytest.fixture def client(): return Client('FOO, BAR', 98763, 1986, '08/19/91', 'MALE') @pytest.fixture(scope='session') def file_name(tmpdir_factory): fn = tmpdir_factory.mktemp('data'

我有一些代码根据传入的id号解析csv中的某些值。为了进行测试,我想使用pytest为CSV创建虚拟数据文件

@pytest.fixture
def client():
    return Client('FOO, BAR', 98763, 1986, '08/19/91', 'MALE')

@pytest.fixture(scope='session')
def file_name(tmpdir_factory):
    fn = tmpdir_factory.mktemp('data'.join('csvNg.csv'))
    headers = ['NAME','PN','MRN','DOB','GENDER']
    with open(fn,'w') as csvfile:
        writer = csv.Dict(csvfile,fieldnames=headers)
        writer.writeheader()
        writer.writerow({'NAME': 'FOO, BAR', 'PN': 98763, 'MRN': 1986, 
            'DOB': '08/19/91', 'GENDER': 'MALE' })
    return str(fn)

def test_locate_ngen():
    FOOBAR = client()
    assert locate_ngen(1986,file_name) == FOOBAR
运行时出现的当前错误:

@pytest.fixture(scope='session')E IsADirectoryError:[Errno 21]为 目录: “/private/var/folders/mn/xg5s_2rd5tbd9hs_ckgwzvtmkqnwq5/T/pytest of ronswanson/pytest-4/cdatavdatadata.datacdatav0”


欢迎来到SO。请看这里,了解如何改进您的问题(格式、校对、提供代码等):并尽量避免使用大写字母;谢谢。当我返回文件名时,它看起来像是作为函数返回的。我一定没有正确使用夹具。这就是我看到的错误。def locate_ngen(mrntoloate,fn):如果不验证_输入(mrntoloate):返回假头=['NAME'、'PN'、'MRN'、'DOB'、'GENDER']>并将open(fn)作为csvFile:E类型错误:应为str、bytes或os.PathLike对象,而不是将open(str(fn),'w')作为csvFile:
fn = tmpdir_factory.mktemp('data').join('csvNg.csv')