Package Depth for XML Report

#28 Declined
Repository
coverage.py
Branch
default
Repository
coverage.py
Branch
default
Author
  1. Lex Berezhny
Reviewers
Description

This is a new feature for XML Report that allows the package names/depth to be controlled via configuration.

See unit tests for example of what it does.

This also fixes issue #235

  • Issues #235: Package name is missing in XML report. resolved

Comments (10)

  1. Ned Batchelder repo owner

    Thanks for the contribution!

    I'm trying to understand how it would work. If I have a class app/sub1/sub2/code.py:MyClass, and I set package_depth to 2, then the XML report would have package="app.sub1", and class="MyClass"? Is that what you want? It seems odd to omit elements of the package. Wouldn't it be better to include all the information in the XML, and let the reporting tool hide information you don't want?

    Maybe I don't understand how the XML report ends up displayed in your environment.

    1. Lex Berezhny author

      My use case is a django project with reports being displayed in jenkins. I think that's a relatively popular use case.

      What this feature allows you to do is to create a report that track apps as single units within a django project. Django projects are designed to be modular by splitting up code into "apps". If you have a very big project, with lots of apps and lots of code/directories in apps it can get rather unwieldy when looking at a coverage report listing.

      If your project looks something like:

      myproj/apps/app1/... myproj/apps/app2/... myproj/apps/app3/...

      You can limit depth to 3 and in jenkins you can easily see report for each "app".

      Jenkins has no feature to limit depth in this way and often people are submitting coverage reports to 3rd party jenkins hosts so adding/modifying this feature in jenkins isn't practical.

      I agree that the report rendering software should have this feature as well but if I already have it working in coverage and there are unit tests for it, what's the harm in having this feature in upstream coverage.py? It's unlikely to be added to jenkins and with system admins who rely on official package distributions it'll be years before the feature makes it on jenkins servers :-)

      1. Ned Batchelder repo owner

        Got it, thanks. And what should the default value and behavior be? BTW: I think I'd prefer not to expose this option on the command line, only in the config file.

        1. Lex Berezhny author

          The default behavior is already there, depth is set to 1, this will produce the same result as coverage did before this feature was introduced.

  2. Ned Batchelder repo owner

    Camilo, I understand the importance of fixing #235, and I'd like to do that. I'm trying to understand what to do with the other feature added here. Do you have an opinion on it?

  3. Ned Batchelder repo owner

    @Lex Berezhny The tests don't pass for me:

    GLOB sdist-make: /Users/ned/coverage/damoti_pr28/setup.py
    py27 inst-nodeps: /Users/ned/coverage/damoti_pr28/.tox/dist/coverage-4.0a0.zip
    py27 runtests: commands[0] | /Users/ned/coverage/damoti_pr28/.tox/py27/bin/python setup.py --quiet clean develop
    py27 runtests: commands[1] | /Users/ned/coverage/damoti_pr28/.tox/py27/bin/python igor.py zip_mods install_egg remove_extension
    py27 runtests: commands[2] | /Users/ned/coverage/damoti_pr28/.tox/py27/bin/python igor.py test_with_tracer py
    === CPython 2.7.2 with Python tracer (/Users/ned/coverage/damoti_pr28/.tox/py27/bin/python) ===
    ..........................................................................................................................................SSS........................................................................................................................................................................................................................................................................................E.
    ======================================================================
    ERROR: test_package_depth_names (tests.test_xml.XmlReportTest)
    ----------------------------------------------------------------------
    Traceback (most recent call last):
      File "/Users/ned/coverage/damoti_pr28/tests/test_xml.py", line 110, in test_package_depth_names
        imp.load_module("proj.apps.app1", *imp.find_module("proj/apps/app1/__init__", ["."]))
    ImportError: No module named proj/apps/app1/__init__
    
    ----------------------------------------------------------------------
    Ran 423 tests in 18.164s
    
    FAILED (SKIP=3, errors=1)
    ERROR: InvocationError: '/Users/ned/coverage/damoti_pr28/.tox/py27/bin/python igor.py test_with_tracer py'
    py27 runtests: commands[3] | /Users/ned/coverage/damoti_pr28/.tox/py27/bin/python setup.py --quiet build_ext --inplace
    clang: warning: argument unused during compilation: '-mno-fused-madd'
    py27 runtests: commands[4] | /Users/ned/coverage/damoti_pr28/.tox/py27/bin/python igor.py test_with_tracer c
    === CPython 2.7.2 with C tracer (/Users/ned/coverage/damoti_pr28/.tox/py27/bin/python) ===
    ..........................................................................................................................................SSS........................................................................................................................................................................................................................................................................................E.
    ======================================================================
    ERROR: test_package_depth_names (tests.test_xml.XmlReportTest)
    ----------------------------------------------------------------------
    Traceback (most recent call last):
      File "/Users/ned/coverage/damoti_pr28/tests/test_xml.py", line 110, in test_package_depth_names
        imp.load_module("proj.apps.app1", *imp.find_module("proj/apps/app1/__init__", ["."]))
    ImportError: No module named proj/apps/app1/__init__
    
    ----------------------------------------------------------------------
    Ran 423 tests in 17.905s
    
    FAILED (SKIP=3, errors=1)
    ERROR: InvocationError: '/Users/ned/coverage/damoti_pr28/.tox/py27/bin/python igor.py test_with_tracer c'
    ________________________________________________________________________ summary _________________________________________________________________________
    ERROR:   py27: commands failed
    
    1. Lex Berezhny author

      The code to create the directories is in the tests: .... self.make_file("proj/apps/app2/init.py", "print('app2')") ....

      Does make_file() no longer do what it did at the time I wrote these tests?

  4. Ned Batchelder repo owner

    @Lex Berezhny I've implemented this feature, though the code had change quite a bit, so I didn't merge the pull request. You can take a look at this commit: 7f119fda7183. One difference: you said the default should be 1 to match the current behavior. After I fixed the regression of not having an XML package name, the default should be 99 (every directory is a package).

    Thanks for the pull request, and sorry it took so long for me to get to.