Visitar URL original
json: show_contexts gives every function and class the whole file's contexts · Issue #2374 · coveragepy/coveragepy · GitHub
Skip to content

json: show_contexts gives every function and class the whole file's contexts #2374

Description

@patrick-immometrica

coverage json --show-contexts adds a contexts dict to every entry under functions and classes, but each of those gets the contexts for the entire file, not just the lines in that function or class.

m.py:

def f():
    return 1

def g():
    return 2

f()
g()
coverage run --context=t1 m.py
coverage json --show-contexts -o out.json

files["m.py"]["functions"]["f"]["contexts"] has lines 1, 2, 4, 5, 7 and 8. I'd expect only line 2.

In jsonreport.py, make_region_data calls contexts_by_lineno() for the whole file and uses the result as is. It also runs that query once per region.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions