Skip to content

Commit

Permalink
fix: silence TypeError during tear down stage
Browse files Browse the repository at this point in the history
  • Loading branch information
lidizheng committed Apr 21, 2022
1 parent f3b72e1 commit a16cf1c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
10 changes: 8 additions & 2 deletions google/auth/transport/requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,14 @@ def __init__(self, session=None):
self.session = session

def __del__(self):
if hasattr(self, "session") and self.session is not None:
self.session.close()
try:
if hasattr(self, "session") and self.session is not None:
self.session.close()
except TypeError:
# NOTE: For certain Python binary built, the queue.Empty exception
# might not be considered a normal Python exception causing
# TypeError.
pass

def __call__(
self,
Expand Down
6 changes: 6 additions & 0 deletions tests/transport/test_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ def test_session_closed_on_del(self):
request.__del__()
http.close.assert_called_with()

http = mock.create_autospec(requests.Session, instance=True)
http.close.side_effect = TypeError("test injected TypeError")
request = google.auth.transport.requests.Request(http)
request.__del__()
http.close.assert_called_with()


class TestTimeoutGuard(object):
def make_guard(self, *args, **kwargs):
Expand Down

0 comments on commit a16cf1c

Please sign in to comment.