Skip to content

Use zero-argument super() #1726

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

Merged
merged 3 commits into from
Nov 2, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
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.
  • Loading branch information
EliahKagan committed Nov 2, 2023
commit 91131770eb0e932b9bc0918fe8374875ecbbd816
10 changes: 2 additions & 8 deletions test/performance/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,7 @@ class TestBigRepoR(TestBase):
"""

def setUp(self):
try:
super().setUp()
except AttributeError:
pass
super().setUp()

repo_path = os.environ.get(k_env_git_repo)
if repo_path is None:
Expand Down Expand Up @@ -64,10 +61,7 @@ class TestBigRepoRW(TestBigRepoR):

def setUp(self):
self.gitrwrepo = None
try:
super().setUp()
except AttributeError:
pass
super().setUp()
dirname = tempfile.mktemp()
os.mkdir(dirname)
self.gitrwrepo = self.gitrorepo.clone(dirname, shared=True, bare=True, odbt=GitCmdObjectDB)
Expand Down