Opened 12 years ago
Last modified 10 years ago
#18586 closed Cleanup/optimization
Rewrite unit tests migrated from doctests — at Initial Version
Reported by: | Michal Petrucha | Owned by: | nobody |
---|---|---|---|
Component: | Testing framework | Version: | dev |
Severity: | Normal | Keywords: | unit tests |
Cc: | Peter Zsoldos, amizya@… | Triage Stage: | Accepted |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | yes | UI/UX: | no |
Description
There's quite a lot of unit tests that have been rewritten 1:1 from doctests. These tests tend to verify all aspects of a certain feature at once, they modify the state of the database throughout the whole test and by the end of the test no one really knows what the database state is supposed to be.
For example, modeltests.generic_relations.GenericRelationsTests.test_generic_relations
walks through most of the features supported by GenericForeignKeys
, it is 130 lines long and in case the last assertion fails, you'll have to spend ridiculous amounts of time figuring out what happened.
A likely incomplete list of similar tests:
modeltests.basic.ModelTest.test_lookup
modeltests.basic.ModelTest.test_object_creation
modeltests.custom_columns.CustomColumnsTests.test_db_column
modeltests.custom_managers.CustomManagerTests.test_manager
modeltests.custom_pk.CustomPKTests.test_custom_pk
modeltests.defer.DeferTests.test_defer
modeltests.expressions.ExpressionsTests.test_filter
modeltests.field_subclassing.CustomField.test_custom_field
modeltests.files.FileStorageTests.test_files
modeltests.get_or_create.GetOrCreateTests.test_get_or_create
modeltests.m2m_recursive.RecursiveM2MTests.test_recursive_m2m
modeltests.m2m_signals.ManyToManySignalsTest
modeltests.m2m_through.M2mThroughTests
modeltests.model_formsets.ModelFormsetTests
modeltests.model_forms.OldFormForXTests.test_with_data
(This one has more than 500 lines!)
modeltests.model_inheritance.ModelInheritanceTests
modeltests.model_package.ModelPackageTests.test_model_packages
modeltests.order_with_respect_to.OrderWithRespectToTests.test_basic
modeltests.signals.SignalTests.test_basic
I only went through modeltests/*/tests.py; I might have overlooked a few tests.
This ticket is meant to track all of them; each time a test is updated, we can strike it out in the list above and once there is no item left, we can close this. The point is to make the test suite help developers as much as possible.