Skip to content

Don't set up monkeypatch and django_db_blocker for every test - #1330

Open
patrick-immometrica wants to merge 1 commit into
pytest-dev:mainfrom
patrick-immometrica:autouse-lazy-fixtures
Open

patrick-immometrica wants to merge 1 commit into
pytest-dev:mainfrom
patrick-immometrica:autouse-lazy-fixtures

Conversation

@patrick-immometrica

Copy link
Copy Markdown

_template_string_if_invalid_marker takes monkeypatch and _django_setup_unittest takes django_db_blocker as arguments. Both are autouse, so pytest resolves the two fixtures for every test, and creates and tears down a MonkeyPatch each time. They are only used for tests marked ignore_template_errors and for unittest classes with databases.

Requesting them with getfixturevalue() where they are needed saves about 8% of the function calls for a file with 5000 empty tests (26.5M to 24.3M under cProfile) and about 5% of the CPU time.

Two autouse fixtures took them as arguments, so pytest resolved them
for every test, although only tests marked ignore_template_errors and
unittest classes with databases use them. Request them where they are
needed instead.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant