pylint-dev / pylint

It's not just a linter that annoys you!
https://pylint.readthedocs.io/en/latest/
GNU General Public License v2.0
5.32k stars 1.14k forks source link

FR: Lint for unittest.TestCase descendants not calling super(…).setUp() #1206

Closed Capstan closed 7 years ago

Capstan commented 7 years ago

I recently introduced a bug where by creating a child test case with a setUp() method without an initial call to super(MyTest, self).setUp(), some necessary calls were omitted. It seems like the following calls in descendants of unittest.TestCase not calling their parents' versions would be worthy of a lint error:

Capstan commented 7 years ago

My follow-up question is, how might one check that these calls exist, and maybe even are the first call (modulo decorator wrappers)?

rogalski commented 7 years ago

@Capstan if you ware willing to implement it, there is a super-init-not-called check, which may be modified for checking for setUp and tearDown inheritance on unittest.TestCase instance.

PCManticore commented 7 years ago

I think this is a bit too specific and I would see it more as an extension, rather than a default check.