py36+ tests are definition ordered [v2] #9144
Merged
+47
−10
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #5196. Closes #7848.
This PR updates @asottile's PR #7848 to also ensure that tests from base classes are ordered before tests defined in the subclasses.
Besides pytest's tests, I also tested it on two projects (using Python 3.9.7):
pytest: the collection tree is the same. Collection time goes from 5.81s to 3.51s.
pandas: the collection tree is almost the same, except 2 test classes where tests from base classes are now ordered before the subclasses (for reference, these are
TestDataFrame(Generic)
,TestCategoricalIndex(Base)
). I think this behavior change is good. Collection time goes from 65.89s to 45.80s.The main speedup comes from avoiding
inspect.getsource()
calls on test class objects, used previously to manually sort by definition order. The function is slow, and I suspect (didn't verify) that it got much slower in Python 3.9 due to some correctness fixes (details here).