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

Faster tests with setUpTestData #3146

Merged
merged 2 commits into from
Dec 11, 2023
Merged

Conversation

dato
Copy link
Contributor

@dato dato commented Dec 5, 2023

Django's TestCase.setUpTestData() allows us to create database fixtures once per test class, instead of once per test method. This speeds up tests considerably.¹

As per the documentation, database fixtures are created once, and roll'd-back to after each test. (Additionally, it is safe to store the resulting models as class variables, since the Python objects are deepcopy()'d from the original before each test.)

I think this could be a nice addition to the BookWyrm codebase.

(¹) On my old laptop, running the whole test suite goes down from ~20min to ~9min (on my newer desktop, it's down to 2min, which is a joy). It seems to go from ~8min to ~4min in the Github runners.

.pylintrc Outdated Show resolved Hide resolved
Pylint's `bad-classmethod-argument` is disabled for each definition
to avoid rewriting the method bodies just to rename `self` → `cls`.
This can be done gradually, as the setUpTestData methods are modified
along the way.
Many tests break without this on newer versions of html-tidy.
@dato dato changed the title rfc: faster tests with setUpTestData Faster tests with setUpTestData Dec 11, 2023
@dato dato marked this pull request as ready for review December 11, 2023 22:48
@mouse-reeve mouse-reeve merged commit 799f842 into bookwyrm-social:main Dec 11, 2023
10 checks passed
@dato dato deleted the setup_test_data branch December 11, 2023 23:46
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.

2 participants