Skip to content

Multiple Static Contexts? #906

Open
Open
@s0undt3ch

Description

@s0undt3ch

Consider the following workflow.

We have project which is tested under several python versions, several OS's, and several versions of said OS's.
For example, we test(short list):

  • Python 2.7:
    • CentOS 7
    • Debian 9
  • Python 3.5:
    • CentOS 7
    • Debian 9
  • Python 3.6:
    • CentOS 7
    • Debian 9

For each of the above we define the following contexts:

  • py2
  • py2.7
  • py3
  • py3.5
  • py3.6
  • centos-7
  • debian-9

I recently took your new context feature for a spin and what I wanted to get was to know which chunks of code run under py2 or py3, which chunks run for CentOS 7, which run for Debian 9, etc...
See where I'm getting at?

Now, the way, we're setting the contexts is more or less like:

if MAYBE_RUN_COVERAGE:
    try:
        import coverage
        if 'COVERAGE_CONTEXTS' in os.environ:
            coverage_contexts = os.environ['COVERAGE_CONTEXTS'].split('||')
            current = coverage.Coverage.current()
            while coverage_contexts:
                context = coverage_contexts.pop(0)
                if not context:
                    continue
                current.switch_context(context)
    except ImportError:
        pass

Of course, as you might have guessed by now, the context feature doesn't work as I envisioned it. Only the last current.switch_context(context) will be used because I'm switching context on the same "frame"?

Looking at the code, it looks like switch_context(context) sets some attributes which, when covered lines are to be recorded, is what's stored in the database.

Would you be against switching/enhancing the feature to use a "stack" of contexts?
This would mean that a covered line could be under several contexts(and the html report seems to suggest that multiple contexts could be shown for a line, although I can only get it to show 1, even if I pass --context at the CLI because you concat that "static" context with the dynamic one.

Is this an approach to contexts that you didn't foresee?
Is this an approach that you actually didn't want to take in the first place?
Would you be open to improving the contexts feature to support this kind of workflow?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions