Commit 56e4a116 authored by Carlos Ramos Carreño's avatar Carlos Ramos Carreño Committed by Jérome Perrin

Fix id tool tests.

Some tests were added to check warnings, which were not working in
Python 2 because the warning message was shown just once.
This is fixed by adding a `warnings.simplefilter("always")` inside
the `catch_warnings` context manager, as recommended in
https://docs.python.org/3/library/warnings.html#testing-warnings .
Note that the previous filter is restored on leaving the context
manager.
parent c3e0cfa3
...@@ -151,6 +151,7 @@ class TestIdTool(ERP5TypeTestCase): ...@@ -151,6 +151,7 @@ class TestIdTool(ERP5TypeTestCase):
# generateNewId expect str, but convert id_group when passed a wrong type # generateNewId expect str, but convert id_group when passed a wrong type
with warnings.catch_warnings(record=True) as recorded: with warnings.catch_warnings(record=True) as recorded:
warnings.simplefilter("always")
self.assertEqual( self.assertEqual(
self.id_tool.generateNewId( self.id_tool.generateNewId(
id_generator=id_generator, id_generator=id_generator,
...@@ -168,6 +169,7 @@ class TestIdTool(ERP5TypeTestCase): ...@@ -168,6 +169,7 @@ class TestIdTool(ERP5TypeTestCase):
id_group='bytes', id_group='bytes',
), 0) ), 0)
with warnings.catch_warnings(record=True) as recorded: with warnings.catch_warnings(record=True) as recorded:
warnings.simplefilter("always")
self.assertEqual( self.assertEqual(
self.id_tool.generateNewId( self.id_tool.generateNewId(
id_generator=id_generator, id_generator=id_generator,
...@@ -269,6 +271,7 @@ class TestIdTool(ERP5TypeTestCase): ...@@ -269,6 +271,7 @@ class TestIdTool(ERP5TypeTestCase):
# generateNewIdList expect str, but convert id_group when passed a wrong type # generateNewIdList expect str, but convert id_group when passed a wrong type
with warnings.catch_warnings(record=True) as recorded: with warnings.catch_warnings(record=True) as recorded:
warnings.simplefilter("always")
self.assertEqual( self.assertEqual(
self.id_tool.generateNewIdList( self.id_tool.generateNewIdList(
id_generator=id_generator, id_generator=id_generator,
...@@ -287,6 +290,7 @@ class TestIdTool(ERP5TypeTestCase): ...@@ -287,6 +290,7 @@ class TestIdTool(ERP5TypeTestCase):
id_count=1, id_count=1,
), [0]) ), [0])
with warnings.catch_warnings(record=True) as recorded: with warnings.catch_warnings(record=True) as recorded:
warnings.simplefilter("always")
self.assertEqual( self.assertEqual(
self.id_tool.generateNewIdList( self.id_tool.generateNewIdList(
id_generator=id_generator, id_generator=id_generator,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment