Don't swallow AttributeError from super().setUp() · gitpython-developers/GitPython@9113177 · GitHub
Skip to content

Commit 9113177

Browse files
committed
Don't swallow AttributeError from super().setUp()
This is conceptually independent of the immediately preceding super() call refactoring, but serves the same goal of simplifying and clarifying super() calls. In test.performance.lib, the TestBigRepoR and TestBigRepoRW classes' setUp methods had calls to setUp through super proxies, which were wrapped in try-blocks to swallow AttributeError exceptions. This removes that, relying on the presence of setUp methods in some parent or sibling class in the MRO. The intent appeared to be solely to account for the possibility that no class in the MRO would define a setUp method. However, the unittest.TestCase base class defines noop setUp and tearDown methods to ensure this does not have to be done. This may also make the code more robust, because the form in which AttributeError was being swallowed was: try: super().setUp() except AttributeError: pass But that has the disadvantage of also catching AttributeError due to a bug or other problem in code that runs *in* an ancestor or sibling class's existing setUp method. This could alternatively be addressed by using: try: other_setUp = super().setUp except AttributeError: pass else: other_setUp() However, because unittest.TestCase provides empty setUp and tearDown methods to allow such special-casing to be avoided (both in cases like this and for the test runner), this isn't needed.
1 parent a47e46d commit 9113177

1 file changed

Lines changed: 2 additions & 8 deletions

File tree

test/performance/lib.py

Lines changed: 2 additions & 8 deletions

0 commit comments

Comments
 (0)