How to organize fixtures when using pytest

前提是你 提交于 2019-12-10 13:47:49

问题


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.)


回答1:


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.



来源:https://stackoverflow.com/questions/15396202/how-to-organize-fixtures-when-using-pytest

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!