首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >brightway2测试:拆卸临时测试项目(装置)

brightway2测试:拆卸临时测试项目(装置)
EN

Stack Overflow用户
提问于 2019-09-04 21:44:18
回答 1查看 52关注 0票数 0

我正在编写一些brightway2扩展,并在pytest中编写相应的测试。我在测试的拆卸部分遇到了问题。

与其他brightway2测试一样,我在创建fixture时使用@bw2test装饰器,请参阅here。这允许在临时目录中创建项目,并且通常会正确配置brightway2以进行测试。

我的fixture看起来像这样:

代码语言:javascript
复制
@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)

这一切都会一直工作到teardown:因为这个项目是temp目录中唯一的项目,所以我得到了ValueError: Can't delete only remaining project

但是,如果我不拆除,那么每次运行测试时创建的新测试目录都会留在磁盘上。它们不是那么大(100kB),但我仍然认为它们不应该存在。

有什么建议吗?

EN

回答 1

Stack Overflow用户

发布于 2019-09-05 17:29:06

不使用projects函数,只需使用shutil.rmtree完全清除目录即可。这在bw2data中是自动完成的,而不是3.5.1 (发布于5.9.2019)。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57789774

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档