Coverage not reported for simple assignments when using the API

Issue #102 resolved
eduardo schettino created an issue

Simple example to reproduce the problem below. The statement "a = 5" is reported as not executed.

{{{ #!python

import coverage

def my_func(): b = 10

def test_coverage(): cov = coverage.coverage() cov.start()

a = 5


if name == "main": test_coverage()


Comments (4)

  1. eduardo schettino reporter

    actually there is no coverage for any statement in the block where the coverage started. coverage is done only inside a new function context.

  2. Ned Batchelder repo owner
    • changed component to docs

    You are right: it only covers code invoked in a function. I'll clarify the docs.

  3. eduardo schettino reporter

    Thanks. Just clarifying the docs is ok. I just notice this while trying something quickly.

    IMO Since the API works like this, it would be clearer if there was a single function that takes a callable instead of a "start", "stop" methods.


    Since we are talking about making the docs clear... I have another suggestion :D

    I also got confused with the section "Measuring Subprocess". It doesn't mention that I need to use "coverage combine"... or maybe just a link to "parallel options" docs would be enough.


  4. Log in to comment