Changeset - 3929ff3f21c6
[Not reviewed]
default
0 1 0
Thomas De Schampheleire - 6 years ago 2019-06-11 20:53:33
thomas.de_schampheleire@nokia.com
Grafted from: 10027d22cd55
tests: introduce doctest_mock_ugettext to allow doctests of localized code

Future doctests will require some extra mocking, as the code-under-test uses
translation (ugettext aka '_') and its provider TurboGears2 needs a context.

Avoid this complexity by mocking ugettext as the identity function. This is
done by providing a pytest fixture 'doctest_mock_ugettext' that will mock
uggettext in the module that uses the fixture.
1 file changed with 13 insertions and 0 deletions:
0 comments (0 inline, 0 general)
conftest.py
Show inline comments
 
@@ -19,6 +19,19 @@ def pytest_ignore_collect(path):
 
        '/kallithea/alembic/env.py',
 
        # collection of the following file messes up the rest of test execution
 
        '/kallithea/tests/scripts/manual_test_concurrency.py',
 
    )
 
    if str(path).endswith(kallithea_ignore_paths):
 
        return True
 

	
 
@pytest.fixture()
 
def doctest_mock_ugettext(request):
 
    """Mock ugettext ('_') in the module using this fixture.
 

	
 
    Intended to be used for doctests.
 

	
 
    In a doctest, enable this fixture using:
 
        >>> getfixture('doctest_mock_ugettext')
 
    """
 
    m = __import__(request.module.__name__, globals(), locals(), [None], 0)
 
    with mock.patch.object(m, '_', lambda s: s):
 
        yield
0 comments (0 inline, 0 general)