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

Refactor test cases to improve unit test quality #3298

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

freddiewanah
Copy link

Hello, first-time submitting PR here.

This PR improves the readability of the assert statements in some of the unit tests by using more expressive assert methods from the unittest module. These changes improve code quality (avoid test smells) by:

  • Making the assert statements more readable, i.e., assertIsNone and assertIsNotNone.

Happy to update more related issues in the test code if needed :)

@bdarnell
Copy link
Member

The assertIsNone and assertIsNotNone changes are good and I'd be happy to see those methods adopted wherever applicable. (The same is true in most cases for all of the new assertion methods that were introduced in python 3, although sometimes it's more subtle and it's not quite equivalent to switch)

For the changes in gen_test that use str.join, though, I prefer them as they are. It's easier to read the single string than the list of string literals.

@freddiewanah
Copy link
Author

Sorry for the late reply. I did more static analysis to the code base during the time and got time to refactor more test cases.
As requested, I've undone the changes in gen_test.py.

In addition, I fixed more inconsistencies in the code, e.g., using assertIn and assertIsNone instead of keep using assertTrue and assertFalse. I found that using more precise assert statement could save the execution time of each individual test methods and hence save the overall project cost during the CICD.

@freddiewanah
Copy link
Author

@bdarnell May I get some updates on this one?

@bdarnell
Copy link
Member

Thanks, all these changes look great. I'm not expecting to see any savings in execution time and CI costs, but the new assertion methods give much better error messages when they fail so this is a worthwhile change. We do have a few black formatting issues (make sure you're using the version specified in requirements.txt), but other than that the PR looks good to merge.

Signed-off-by: Han Wang <freddie.wanah@gmail.com>
@freddiewanah
Copy link
Author

Thanks for the review, and I've pushed a new commit to fix the format issue. Sorry about the previous check failed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants