-
Notifications
You must be signed in to change notification settings - Fork 203
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
use better test assertions by replacing use of assertFalse/assertTrue #4170
Conversation
77a99a8
to
6c5b4c3
Compare
Replace `self.assertTrue(False, ...` and similar by appropriate assert functions. This avoids redundancy and potential mistakes and improves error reporting.
LMod ignores $LC_ALL and uses $LANG so set that too for the tests. The output of running `thisshouldfail` may be "bash: line 1: thisshouldfail: command not found" depending on the bash version, so adjust the regex
`assertTrue(somelist, otherlist)` will not trigger a failure when it should as `assertEqual` was intended
6c5b4c3
to
cbcfdf7
Compare
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.
@Flamefire Thanks a lot for the effort here, makes a lot of sense.
Before I start wading through this to make sure we're not accidentally introducing a check that always passes, I think it makes sense to prevent that we re-introduce the use of self.assertFalse
or self.assertTrue
.
For this, we should add a test in test/framework/general.py
that searches for the use of these, and fails if it finds any?
That can be done by iterating over all test/framework/*.py
files, and using "\s+self\.assert(False|True)
" as regex, I think...
edit: nevermind, not all assertFalse
/assertTrue
are removed here, so that won't work...
There are cases where those make sense. E.g. one compares the GITHUB_TOKEN and purposely is not using Of course we could use Other solution: Switch to pytest and use |
There's definitely advantages in a switch to It would be nice if we could outline some "best practices" in the EasyBuild documentation w.r.t. writing tests, to add to https://docs.easybuild.io/en/latest/Unit-tests.html |
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.
lgtm
Spent some time scrolling through this, didn't spot anything suspicious that would require changes, so good to go. Thanks a lot for the effort here @Flamefire! |
Replace
self.assertTrue(False, ...
and similar by appropriate assert functions. This avoids redundancy and potential mistakes and improves error reporting.I checked that all functions are available in Python 2.7 and 3.1+
Especially the
assertTrue(False
were annoying as the error message started with "Assertion failed: False is not True"Most of the
assert[Not]In
replace the need to duplicate the arguments in the message which sometimes got forgotten.Mostly done by a RegEx search&replace so should be save.
I also fixed a bug in the test:
Here
assertEqual
was intended as shown by the 2nd parameter. Another reason why we should try to avoid the genericassertTrue/False
tests