use better test assertions by replacing use of assertFalse/assertTrue#4170
use better test assertions by replacing use of assertFalse/assertTrue#4170boegel merged 3 commits intoeasybuilders:developfrom
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.
@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 |
|
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(Falsewere annoying as the error message started with "Assertion failed: False is not True"Most of the
assert[Not]Inreplace 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
assertEqualwas intended as shown by the 2nd parameter. Another reason why we should try to avoid the genericassertTrue/Falsetests