Python金字塔i18n和pytest

问题描述

我跟随pyramid i18nlocale下将翻译添加到我的应用程序中,效果很好,但是pytest一点都不高兴-我遇到这样的错误

    def _isdir(self,path):
>       raise NotImplementedError(
            "Can't perform this operation for unregistered loader type"
        )
E       pyramid.exceptions.ConfigurationExecutionError: <class 'NotImplementedError'>: Can't perform this operation for unregistered loader 

app/__init__.py使用config.add_translation_dirs('app:locale/')添加翻译

pytest.ini

[pytest]
testpaths = tests
python_files = *.py
addopts = -p no:warning

结构是

app/
tests/
setup.py
pytest.ini
...

谢谢

PS:如果添加变形平移,我会发现相同的问题

解决方法

我怀疑您在测试中没有正确调用config.begin()config.end(),因此线程本地处于活动状态。这完全取决于测试的外观,但这实际上意味着什么。 Pyramid的i18n系统依赖于在测试期间正确推入线程局部。