pybuilder: Missing "def" line coverage

I noticed that coverage was not counting my def lines as covered and some googling revealed this on coverage.py FAQ:

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

This happens because coverage.py is started after the functions are defined. The definition lines are executed without coverage measurement, then coverage.py 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.py earlier. If you use the command line to run your program with coverage.py, 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. – http://coverage.readthedocs.io/en/latest/faq.html#faq

What must I do to get coverage reporting to see these def lines? Or can I globally suppress them?

https://www.evernote.com/l/AAKeWb3SOf1G7JwooAcg2i6USWh0B3ZrOgc

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 17 (9 by maintainers)

Most upvoted comments

You’re welcome. 😃 Could be closed?

It looks like that it’s time to write pybuilder_pytest_coverage plugin. 😃

OK. I switched over… can py.test break the build if coverage is < X%?

Update: looks like this works: project.get_property("pytest_extra_args").append("--cov-fail-under=100")

@jduprey Did You try to use project.set_property('coverage_reset_modules', True)?

PS I see that we need to update documentation about coverage properties 😦

  1. Platform you’re running on?
  2. Version of PyB?
  3. Version of Python?