本文介绍了使用pytest时如何组织装置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

固定装置往往较小且可重复使用.鉴于特定的灯具可以依靠其他灯具

Fixtures tend to be small and reusable. Given that a specific fixture can rely on other fixtures

@pytest.fixture
def Account(db, memcache):
    ...

我想将我的灯具组织在模块中,并像这样(例如)将它们导入特定的测试文件中

I would like to organize my fixtures in modules, and import them in a specific test-file like so (e.g.)

from .fixtures.models import Account

不幸的是,这似乎不起作用.相反,我总是也必须导入所有从属灯具,例如

Unfortunately this does not seem to work. Instead I always have to import all subordinate fixtures too, e.g.

from .fixtures.models import Account, db, memcache

拥有细粒度,可重复使用的固定装置并使它们在模块级别可访问的更好方法是什么? (竞赛在程序包/目录级别起作用.)

What is the better approach to have fine-grained small, reusable fixtures and make them accessible on a module level. (conftest works on the package/directory level.)

推荐答案

通常我不建议这样做,但是如果您的模块包含一组特定的灯具(相互依赖),那么from .fixtures.models import *可能是可行吗目前,我想不出另一个通用的解决方案,它可以避免在导入测试模块中了解底层夹具的依赖关系.

Usually i don't recommend this but if you have modules containing a specific set of fixtures (Which depend on each other), then maybe from .fixtures.models import * would be workable? I can't think of another generic solution at the moment which would avoid knowing the underlying fixture dependencies in the importing test module.

这篇关于使用pytest时如何组织装置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-08 23:55