pytest插件来验证在测试中使用envvars
pytest-envvars的Python项目详细描述
pytest插件,用于验证在测试中是否使用envvars
什么是pytest envvars?
pytest环境变量随机化单元测试中环境变量的值,以检查有关配置的模拟的一致性。如果测试有一个错误的模拟,这个测试将被破坏。
安装
$ pip install pytest-envvars
使用
您需要对pytest.ini文件进行一些更改,例如…
[pytest]pytestenvvars__env_files= .env pytestenvvars__dont_randomize_envvars= CACHE_URL
在上面的这个例子中,插件读取项目的.envfile(来自pytestenvvars__env_filessection)并随机化该文件上的allenvvar配置,如果不需要随机化某些envvar配置,则需要将此envvar添加到pytestenvvars__dont_randomize_envvarssection,如上图所示。