我正在编写一些brightway2扩展,并在pytest中编写相应的测试。我在测试的拆卸部分遇到了问题
与其他brightway2测试一样,我在创建夹具时使用@bw2tests装饰器,请参见here。这允许在temp dir中创建项目,并且通常为测试正确配置brightway2
我的固定装置如下所示:
@pytest.fixture
@bw2test
def basic():
"""Pytest fixture with test bw2 project with test data to use in test"""
# Write test data...
# For example, for the biosphere Database:
biosphere = Database("biosphere")
biosphere.register()
biosphere.write({
("biosphere", "1"): {
'categories': ['things'],
'exchanges': [],
'name': 'an emission',
'type': 'emission',
'unit': 'kg'
})
# Once I have created all the data I need,
# I yield the data I need for my test functions...
yield {'project': projects.current, 'method_name': method_name}
# Once my tests are done, I would like to tear down the project
projects.delete_project(projects.current, delete_dir=True)
这一切都会一直工作到拆卸:因为项目是temp目录中唯一的一个,所以我得到ValueError: Can't delete only remaining project
但是,如果我不拆除,每次运行测试时创建的新测试目录将保留在磁盘上。它们没有那么大(100kB),但我仍然认为它们不应该存在
有什么建议吗
不使用
projects
函数,只需使用shutil.rmtree
完全取消目录。与3.5.1版(2019年9月5日发布)相比,现在在bw2data
中自动完成相关问题 更多 >
编程相关推荐