-
Notifications
You must be signed in to change notification settings - Fork 121
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
test: refactor asserts to pytest style #1191
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks really good, thanks! It's a pity pytestify doesn't do more for us, like assertRaises. We could try to fix it ourselves, but I don't think it's worth it. I think the new asserts are much easier to read. And thanks for doing the coverage diff -- looks good!
Just one comment about the assert
statement in lambdas: I'd like to improve the error messages in those cases if possible.
Also, if you've modified pytestify, do you have a link to the diff for the modified version (on your own fork)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still need to review the 7 large files - will come back to that later today.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! LGTM :)
Refactor unittest self.assert to pytest assert style.
I used a modified version of pytestify, so that it only converts the assertions without changing anything else. This will be phase 1 of our unittest-pytest conversion.
Commits Explained
The first commit is 100% generated by pytestify, there is no need to review it.
After the first commit, two test files weren't processed because of bugs in pytestify, which I couldn't be bothered to fix, so I did 3 separate commits to hack the test cases to make pytestify work and revert the hacks:
These three continuous commits are only meant to make pytestify work on certain test files.
At this point, the UT still fails.
The fifth commit is where the major manual work is done and made the test pass. Please spend most of your time reviewing this commit since it's where the manual work is. Major changes include:
self.assertRaises
andwith self.assertRaisesRegex
which pytestify couldn't handleThere might be more types of changes that I have forgotten because it took quite some time to work on every single test file.
The sixth commit is a minor change where an exception is added to
pyproject.toml
to make one UT pass.Before/After UT Result Comparison
TL;DR: According to UT statistics, the number of test cases is the same after the refactor, there isn't any test case accidentally left behind.
Before refactoring:
After refactoring:
Note that at the moment this branch is out of date with the main branch because after checking out this branch new changes including tests are made to the main branch. Since I suppose the reviewing of this PR could take some time, I will not try to sync with the main branch multiple times to work out the conflicts. I will take a final merge and conflict-solving after review, I hope this is OK.