You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
gets the response again for each test function, but this is more isolation than I need as my tests don't modify the response. I'd like response to be class scoped to improve performance, but django_app is function scoped. The only way of changing the scope that I can think of is copy pasting the response fixture, and recursively all of its dependencies to change the scope:
This also assumes the function scoped django_app is not set up in case it would interfere; it's not needed by these tests, but it is used by other tests outside of this class. The alternative is to simply merge all tests into 1, but I'd rather avoid that.
Is there perhaps some juicy feature I'm overlooking?
Unfortunately I don't think there's any easy solution to this; if your django application does not hold state, perhaps you can change it into a session-scoped fixture instead? You probably only need to actually cleanup/rollback the database before each test, not the django_app object. @pytest-dev/pytest-django-developers might have other thoughts/suggestions.
Thanks, that answers my question. For the record, I've mixed things up a bit when simplifying my example; django_app does not depend on db, but my response fixture depends on user which depends on db etc. I could try a session scoped django app since it has no dependencies.
Activity
pytestbot commentedon Apr 9, 2018
GitMate.io thinks possibly related issues are #538 (Fixture scope documentation), #2246 (Question regarding fixture visibility), #1588 (Proposal to expand fixtures), #1461 (Suggestion: merge .fixture and .yield_fixture), and #1681 (invocation-scoped fixtures).
nicoddemus commentedon Apr 9, 2018
Unfortunately I don't think there's any easy solution to this; if your django application does not hold state, perhaps you can change it into a
session-scoped fixture instead? You probably only need to actually cleanup/rollback the database before each test, not the django_app object. @pytest-dev/pytest-django-developers might have other thoughts/suggestions.hannahdiels commentedon Apr 10, 2018
Thanks, that answers my question. For the record, I've mixed things up a bit when simplifying my example;
django_appdoes not depend ondb, but myresponsefixture depends onuserwhich depends ondbetc. I could try a session scoped django app since it has no dependencies.nicoddemus commentedon Apr 10, 2018
@timdiels thanks for the follow up. Can we close this?
hannahdiels commentedon Apr 10, 2018
Yes