我正在编写一些brightway2 扩展,并在pytest 中编写相应的测试。我在测试的拆卸部分遇到问题。
像其他 brightway2 测试一样,我在创建我的夹具时使用 @bw2tests 装饰器,请参见此处。这允许在临时目录中创建项目,并且通常会正确配置 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),但我仍然认为它们不应该存在。
有什么建议么?