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

py36+ tests are definition ordered [v2] #9144

Merged
merged 2 commits into from Oct 1, 2021

Conversation

bluetech
Copy link
Member

@bluetech bluetech commented Oct 1, 2021

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).

Copy link
Member

@nicoddemus nicoddemus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Copy link
Member

@RonnyPfannschmidt RonnyPfannschmidt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😀

Copy link
Member

@asottile asottile left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice! that was even simpler than I thought it was going to be!

changelog/5196.feature.rst Outdated Show resolved Hide resolved
Co-authored-by: Anthony Sottile <asottile@umich.edu>
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.

Use simple definition order in Python>3.6
4 participants