Skip to content

Commit

Permalink
fix: make the warnings tests behave same on python3.10
Browse files Browse the repository at this point in the history
On Python 3.10 django emits a warning (DeprecationWarning) for asyncio
run
- https://stackoverflow.com/questions/70303895/python-3-10-asyncio-gather-shows-deprecationwarning-there-is-no-current-event

We filter out this warning here, since it is not relevant to our test
and still have the tests in place so that I can check for this
behaviour.

- Github Issue: #7183

Authored-by: Vinit Kumar <vinit.kumar@socialschools.nl>
Signed-off-by: Vinit Kumar <vinit.kumar@socialschools.nl>
  • Loading branch information
vinitkumar committed Jan 16, 2022
1 parent c72d772 commit 769b729
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 16 deletions.
13 changes: 11 additions & 2 deletions cms/test_utils/testcases.py
Expand Up @@ -448,12 +448,21 @@ def update(self, response):

def failUnlessWarns(self, category, message, f, *args, **kwargs):
warningsShown = []
cleanwarningsShown = []
result = _collectWarnings(warningsShown.append, f, *args, **kwargs)

if not warningsShown:
self.fail("No warnings emitted")
first = warningsShown[0]
for other in warningsShown[1:]:

for warning in warningsShown:
# this specific warning is present due to the way Django
# handle asyncio
# https://stackoverflow.com/questions/70303895/python-3-10-asyncio-gather-shows-deprecationwarning-there-is-no-current-event
if (warning.category != DeprecationWarning and warning.message != 'There is no current event loop'):
cleanwarningsShown.append(warning)

first = cleanwarningsShown[0]
for other in cleanwarningsShown[1:]:
if ((other.message, other.category) != (first.message, first.category)):
self.fail("Can't handle different warnings")

Expand Down
25 changes: 11 additions & 14 deletions cms/tests/test_plugins.py
Expand Up @@ -891,20 +891,17 @@ def test_page_attribute_warns(self):
def get_page(plugin):
return plugin.page


# fails due to issue with django
# todo: rewrite it or upgrade django
# self.assertWarns(
# DontUsePageAttributeWarning,
# "Don't use the page attribute on CMSPlugins! CMSPlugins are not guaranteed to have a page associated with them!",
# get_page, a
# )
# same as above
# with warnings.catch_warnings(record=True) as w:
# warnings.simplefilter('always')
# a.page
# self.assertEqual(1, len(w))
# self.assertIn('test_plugins.py', w[0].filename)
print(DontUsePageAttributeWarning)
self.assertWarns(
DontUsePageAttributeWarning,
"Don't use the page attribute on CMSPlugins! CMSPlugins are not guaranteed to have a page associated with them!",
get_page, a
)
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter('always')
a.page
self.assertEqual(1, len(w))
self.assertIn('test_plugins.py', w[0].filename)

def test_editing_plugin_changes_page_modification_time_in_sitemap(self):
now = timezone.now()
Expand Down

0 comments on commit 769b729

Please sign in to comment.