强制 pytest.main() 使用不同的 pytest.ini

Lom*_*bax 3 python pytest

有没有办法将 pytest 指向不同的 pytest.ini 文件?

我正在处理的应用程序有一个 pytest.ini 文件,用于在启动时运行单元测试,我不想修改该文件。

但是,在通过 pytest.main() 运行我的自动化测试时,我确实想将 pytest 指向不同的文件

pytest.main(['-p', 'no:django', '-v', '--json-report', '-m', test_marker])
Run Code Online (Sandbox Code Playgroud)

有没有办法告诉 pytest 使用另一个位置的 pytest.ini 文件?

phd*_*phd 6

$ pytest --help | grep -F config
  -c file               load configuration from `file` instead of trying to
                        locate one of the implicit configuration files.
Run Code Online (Sandbox Code Playgroud)

那是,

pytest.main(['-c', 'pytest-alt.ini'])
Run Code Online (Sandbox Code Playgroud)