4

I got some of our project packages installed in a venv by a jenkins job. After installing, the job pulls some unittests from a separate repository and runs them against the installed package.

My problem is coverage only covers the test scripts but not the installed packages.

Here's the folder structure:

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

So for further explanation, I iterate over the packages in MyProject, checkout the tests for each one into temp_tests, cd in temp_tests and call nose2 -t ..\..\..\Venv\Lib\site-packages

I thought the -t param would set the top level directory, and use the stuff installed there. And yes, the tests run succesfully. But the coverage only covers the test suites themselves. Is there a way to tell nose to do the coverage for the installed package?

For completeness here my 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

and .coveragerc:

# .coveragerc
[run]
branch = True
[report]
show_missing = True
omit = 
    build/*
    tests/*
    setup.py
    */__init__.py
Igl3
  • 4,900
  • 5
  • 35
  • 69

2 Answers2

2

I solved my problem by using the coverage package after testing.

I did:

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

where the folder tests is containing my tests.

My unittest.cfg is set to:

[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

And in .coveragerc I excluded all unwanted (system) packages:

# .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
Igl3
  • 4,900
  • 5
  • 35
  • 69
0

The coverage plugin of nose2 provides an option to define the PATH where to measure coverage, --coverage PATH. PATH will accept multiple directories in the usual shell syntax. I suggest this command line:

nose2 -t ..\..\..\Venv\Lib\site-packages --coverage ..\..\..\Venv\Lib\site-packages
yacc
  • 2,915
  • 4
  • 19
  • 33
  • 1
    Note that's just a guess since I don't have nose2 and Linux ready right now. Let me know how it works. – yacc Sep 04 '17 at 23:43