Skip to content

Commit

Permalink
Introduce assertWarningIn helper
Browse files Browse the repository at this point in the history
In some cases, some deprecation messages may be generated by third-party libraries depedending
on the python version we are using.

This is a problem when we want to insure that a specific message is raised.

This change introduce `assertWarningIn`, which will check if a specific deprecation warning
is in the list of warnings.
  • Loading branch information
chantra committed Jun 12, 2023
1 parent c3a2d35 commit ffdbe46
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
11 changes: 11 additions & 0 deletions tests/Framework.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,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):
Expand Down
2 changes: 1 addition & 1 deletion tests/GithubApp.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def testGetAuthenticatedApp(self):
with self.assertWarns(DeprecationWarning) as warning:
app = self.g.get_app()

self.assertWarning(
self.assertWarningIn(
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 ffdbe46

Please sign in to comment.