Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to organize fixtures when using 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.)

like image 522
herr.kaste Avatar asked Nov 12 '22 09:11

herr.kaste


1 Answers

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.

like image 133
hpk42 Avatar answered Nov 14 '22 23:11

hpk42