运行nose2,覆盖已安装的软件包

时间:2017-08-24 12:32:19

标签: python-3.x unit-testing jenkins code-coverage nose2

我通过jenkins工作在venv安装了一些项目包。安装后,该作业从单独的存储库中提取一些单元测试,并针对已安装的包运行它们。

我的问题是coverage只涵盖了测试脚本,但没有涵盖已安装的软件包。

这是文件夹结构:

JenkinsWorkspace
|_Venv
|_MyProject
  |_trunk
    |_Python   
    |_Package1
    |_Package2
      |_temp_tests
        |_test_suite1.py
        |_...

因此,为了进一步说明,我会迭代MyProject中的包,检查每个包中的temp_testscd中的temp_tests的测试并调用nose2 -t ..\..\..\Venv\Lib\site-packages }

我认为-t param会设置顶级目录,并使用那里安装的东西。是的,测试成功运行。但coverage仅涵盖测试套件本身。 有没有办法让鼻子对已安装的包裹进行覆盖?

为了完整性,我的unittest.cfg

[coverage]
coverage-report = term-missing
always-on = True
coverage-config = .coveragerc

[junit-xml]
always-on = True
keep_restricted = False
path = nose2-junit.xml
test_fullname = False

.coveragerc

# .coveragerc
[run]
branch = True
[report]
show_missing = True
omit = 
    build/*
    tests/*
    setup.py
    */__init__.py

2 个答案:

答案 0 :(得分:1)

我在测试后使用coverage包解决了我的问题。

我做了:

nose2 --plugin nose2.plugins.junitxml -s tests -c unittest.cfg
python -m coverage xml

文件夹tests包含我的测试。

我的unittest.cfg设置为:

[coverage]
coverage-report = term-missing
always-on = True
coverage-config = .coveragerc

[junit-xml]
always-on = True
keep_restricted = False
path = nose2-junit.xml
test_fullname = False

.coveragerc中,我排除了所有不需要的(系统)包:

# .coveragerc
[run]
branch = True
[report]
show_missing = True
omit = 
    build/*
    tests/*
    setup.py
    */__init__.py
    */nose/*
    */pkg_resources/*
    */six.py
    */nose2/*
    */coverage/*
    */cov_core.py

答案 1 :(得分:0)

nose2的coverage插件提供了一个选项,用于定义PATH测量覆盖范围的位置--coverage PATH。 PATH将以通常的shell语法接受多个目录。我建议这个命令行:

nose2 -t ..\..\..\Venv\Lib\site-packages --coverage ..\..\..\Venv\Lib\site-packages