forked from github/pelican
Make sure locale is what we want before/after the tests
The locale is a global state, and it was not properly reset to
whatever it was before the unitttest possibly changed it.
This is now fixed.
Not restoring the locale led to weird issues: depending on
the order chosen by "python -m unittest discover" to run
the unit tests, some tests would apparently randomly fail
due to the locale not being what was expected.
For example, test_period_in_timeperiod_archive would
call mock('posts/1970/ 1月/index.html',...) instead of
expected mock('posts/1970/Jan/index.html',...) and fail.
This commit is contained in:
parent
e97e9b5ae5
commit
7277c95fb5
7 changed files with 44 additions and 2 deletions
|
|
@ -4,6 +4,7 @@ from __future__ import unicode_literals, absolute_import
|
|||
import six
|
||||
from datetime import datetime
|
||||
from sys import platform
|
||||
import locale
|
||||
|
||||
from pelican.tests.support import unittest, get_settings
|
||||
|
||||
|
|
@ -22,6 +23,8 @@ class TestPage(unittest.TestCase):
|
|||
|
||||
def setUp(self):
|
||||
super(TestPage, self).setUp()
|
||||
self.old_locale = locale.setlocale(locale.LC_ALL)
|
||||
locale.setlocale(locale.LC_ALL, str('C'))
|
||||
self.page_kwargs = {
|
||||
'content': TEST_CONTENT,
|
||||
'context': {
|
||||
|
|
@ -35,6 +38,9 @@ class TestPage(unittest.TestCase):
|
|||
'source_path': '/path/to/file/foo.ext'
|
||||
}
|
||||
|
||||
def tearDown(self):
|
||||
locale.setlocale(locale.LC_ALL, self.old_locale)
|
||||
|
||||
def test_use_args(self):
|
||||
# Creating a page with arguments passed to the constructor should use
|
||||
# them to initialise object's attributes.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue