Skip to content

Avoid slow database serialization when possible #1184

@bluetech

Description

@bluetech

I have a large project where the serialize_db_to_string function from Django takes around 5s on every call to pytest. This DB has some pre-loaded fixtures so it doesn't start the test run empty.

The relevant Django code is:

https://github.com/django/django/blob/02a5cbfe76382da2a0414df17017185be5bd47f9/django/test/utils.py#L231-L239

This is called from pytest-django django_db_setup session fixture:

db_cfg = setup_databases(
verbosity=request.config.option.verbose,
interactive=False,
**setup_databases_args,
)

We don't pass any of the serialize parameters so it defaults to serializing.

The Django DiscoverRunner doesn't always serialize:

https://github.com/django/django/blob/02a5cbfe76382da2a0414df17017185be5bd47f9/django/test/runner.py#L1081-L1089

It only serializes if there are any tests in the suite which use serialized_rollback:

https://github.com/django/django/blob/02a5cbfe76382da2a0414df17017185be5bd47f9/django/test/runner.py#L1044-L1056

We should try to do the same if possible.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions