gpt4 book ai didi

python-3.x - Pytest 创建要读取的临时 CSV 文件

转载 作者:行者123 更新时间:2023-12-04 16:45:32 24 4
gpt4 key购买 nike

我有一些代码可以根据传入的 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] Is a directory: '/private/var/folders/mn/xg5s_2rd5tbd9hs_ckgwzvtmkqnwq5/T/pytest-of-ronswanson/pytest-4/cdatasdatavdataNdatagdata.datacdatasdatav0'

最佳答案

fn = tmpdir_factory.mktemp('data').join('csvNg.csv')

关于python-3.x - Pytest 创建要读取的临时 CSV 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49949456/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com