Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do common db setup between tests once #105

Closed
alvinchow86 opened this issue Jun 11, 2014 · 4 comments
Closed

Do common db setup between tests once #105

alvinchow86 opened this issue Jun 11, 2014 · 4 comments

Comments

@alvinchow86
Copy link

It would be useful if I could do some common database setup that's shared between tests (like loading some large fixture data or something), just once for the test run rather than for every test, for faster performance. The test would still be wrapped in a transaction, so any db changes in tests would be rolled back to the original state.

However this doesn't seem possible in pytest_django, since the db fixture is only function scoped, whereas I might want to do this database setup on a module or session scope.

@Stranger6667
Copy link

I think it can be done with some kind of ordering/grouping of tests execution. E.g.:

  1. Execute tests, which requires db-fixture-1
  2. Execute tests, which requires db-fixture-2
  3. ???????
  4. PROFIT

I've done some kind of similar features in my project, but it is still non-usable draft, which works only in few cases :( But it speeds up part of my test suite to run 5-6 times faster than before. Actually it depends on complexity of DB fixture.
Anyway, it would be very nice feature, but not trivial to implement.

@ktosiek
Copy link
Contributor

ktosiek commented Nov 3, 2014

for session-scoped data you can tap into _django_db_setup as a workaround:

@pytest.fixture(scope='session')
def _django_db_setup(_django_db_setup, _django_cursor_wrapper):
    from django.core import management
    with _django_cursor_wrapper:
        management.call_command('loaddata', 'global_test_fixture_1', 'global_test_fixture_2')
    return _django_db_setup

I'd be interested in having this for smaller scopes - maybe using some kind of subtransactions.

@rbiersbach
Copy link

We also have a problem with this as we are using parameterize a lot for read-only access.
We have a workaround but that just feels super awkward compared to the scopes which are intended for this purpose originally.

@bluetech
Copy link
Member

We are having some overlapping discussion on this in #514, I'll close this one in favor of that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants