我已经使用以下命令安装了nose2:
pip3 install nose2
我已经使用以下命令在自定义路径中安装了覆盖范围:
pip3 install --target=/tmp/coverage_pkg coverage
我想执行测试用例并生成覆盖率报告。有没有办法将我安装在自定义路径中的覆盖插件映射到nose2?
我尝试执行以下命令:
nose2 --with-coverage
我得到以下输出:
Warning: you need to install "coverage_plugin" extra requirements to use this plugin. e.g. `pip install nose2[coverage_plugin]`
----------------------------------------------------------------------
Ran 0 tests in 0.000s
OK
我想使用自定义路径中安装的覆盖率包生成覆盖率报告。
有人可以解释一下我是否可以实现这一目标吗?
最佳答案
我能够使用以下命令实现此目的:
cd <custom location where packages are installed>
python3 -m nose2 --with-coverage -s "path_to_source_dir" --coverage "path_to_source_dir"
您需要留在安装nose2和coverage的位置(自定义目录/例如:/tmp/coverage_pkg)。
要进行更多配置并生成 junit 报告和覆盖率报告,我们可以使用 unittest.cfg
文件和 .coveragerc
来控制覆盖率报告和单元测试。
示例unittest.cfg
:
[unittest]
plugins = nose2.plugins.junitxml
start-dir =
code-directories =
test-file-pattern = *_test.py
test-method-prefix = t
[junit-xml]
always-on = True
keep_restricted = False
path = nose2-junit.xml
test_fullname = False
[coverage]
always-on = True
coverage =
coverage-config = .coveragerc
coverage-report = term-missing
xml
示例.coveragerc
:
[run]
branch = True
[xml]
output =coverage.xml
[report]
show_missing = True
omit=
/test/*
/poc1.py
/bin/__init__.py
使用以下命令使用配置文件并生成单元测试报告和覆盖率报告。
python3 -m nose2 --config "<path to config file>/unittest.cfg"
关于python - 有没有办法将 python nos2 映射到安装在自定义位置的覆盖插件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74449669/