Skip to content

Commit

Permalink
[tests] filter httpretty warnings and replace assertWarningIn with as…
Browse files Browse the repository at this point in the history
…sertWarning
  • Loading branch information
chantra committed Jun 16, 2023
1 parent 15dcb09 commit 8b1df3f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 16 deletions.
24 changes: 9 additions & 15 deletions tests/Framework.py
Expand Up @@ -325,23 +325,17 @@ def tearDown(self):
def assertWarning(self, warning, expected):
self.assertWarnings(warning, expected)

def assertWarningIn(self, warning, expected):
for message in warning.warnings:
if (
isinstance(message, warnings.WarningMessage)
and isinstance(message.message, DeprecationWarning)
and message.message.args == (expected,)
):
return

assert False, f"Warning *{expected}* not found in *{warning.warnings}*"

def assertWarnings(self, warning, *expecteds):
self.assertEqual(len(warning.warnings), len(expecteds))
for message, expected in zip(warning.warnings, expecteds):
self.assertIsInstance(message, warnings.WarningMessage)
self.assertIsInstance(message.message, DeprecationWarning)
self.assertEqual(message.message.args, (expected,))
actual = [
(type(message), type(message.message), message.message.args)
for message in warning.warnings
]
expected = [
(warnings.WarningMessage, DeprecationWarning, (expected,))
for expected in expecteds
]
self.assertSequenceEqual(actual, expected)

def __openFile(self, mode):
for (_, _, functionName, _) in traceback.extract_stack():
Expand Down
7 changes: 6 additions & 1 deletion tests/GithubApp.py
Expand Up @@ -106,9 +106,14 @@ def testGetAuthenticatedApp(self):
g = github.Github(auth=auth)

with self.assertWarns(DeprecationWarning) as warning:
# we ignore warnings from httpretty dependency
import warnings

warnings.filterwarnings("ignore", module="httpretty")

app = g.get_app()

self.assertWarningIn(
self.assertWarning(
warning,
"Argument slug is mandatory, calling this method without the slug argument is deprecated, "
"please use github.GithubIntegration(auth=github.Auth.AppAuth(...)).get_app() instead",
Expand Down

0 comments on commit 8b1df3f

Please sign in to comment.