Does coverage.py measure the function and class definitions?

前端 未结 2 1517
终归单人心
终归单人心 2020-12-16 13:24

I am trying to achieve a 100% coverage for a basic python module. I use Ned Batchelder\'s coverage.py module to test it.

1 class account(object):
2   def __i         


        
相关标签:
2条回答
  • 2020-12-16 13:57

    I think your problem is described in the FAQ:

    Q: Why do the bodies of functions (or classes) show as executed, but the def lines do not?

    This happens because coverage is started after the functions are defined. The definition lines are executed without coverage measurement, then coverage is started, then the function is called. This means the body is measured, but the definition of the function itself is not.

    To fix this, start coverage earlier. If you use the command line to run your program with coverage, then your entire program will be monitored. If you are using the API, you need to call coverage.start() before importing the modules that define your functions.

    0 讨论(0)
  • 2020-12-16 14:05

    Following jcollado's answer:

    I have this problem with Django nose which only covers lines used by tests.

    For fix it I launch firstly manage.py with coverage and after I launch tests. .coverage file will contain both's reports.

    My first command is a custom which prints my project settings. Example:

    coverage run ./manage.py settings && ./manage.py test myapp
    
    0 讨论(0)
提交回复
热议问题