外掛範圍¶
針對 pytest 外掛取得範圍是一個非常特殊的情況。因為 pytest 實作外掛的方式(使用 setuptools 進入點),它不允許控制外掛載入的順序。有關技術詳細資料,請參閱 pytest/issues/935 。
目前處理這個問題的方式是使用附加功能並手動啟動 pytest-cov
的引擎,例如
COV_CORE_SOURCE=src COV_CORE_CONFIG=.coveragerc COV_CORE_DATAFILE=.coverage.eager pytest --cov=src --cov-append
或者,你也可以在 tox.ini
中執行這個動作(當然,如果你正在使用 Tox 的話)
[testenv]
setenv =
COV_CORE_SOURCE=
COV_CORE_CONFIG={toxinidir}/.coveragerc
COV_CORE_DATAFILE={toxinidir}/.coverage
以及在 pytest.ini
/ tox.ini
/ setup.cfg
[tool:pytest]
addopts = --cov --cov-append