Variable assignment with an if-else statement is not considered as branched

Issue #606 closed
Federico Carrá created an issue

Hello. In my code I have a variable assignment with a if-else statement as this one:

variable = 1 if some_condition else -1

When doing coverage --with-branches, it does not consider that this has branches.

Comments (7)

  1. Ned Batchelder repo owner

    Branch coverage can only measure branching from one line to another, since Python's trace facility currently only supports per-line tracing. 3.7 introduces opcode-level tracing, though will need significant changes to make use of it.

  2. Ned Batchelder repo owner
    • changed status to open

    This would be a huge amount of work (how do you report on this?), but it's a reasonable feature idea.

  3. Federico Carrá reporter

    Maybe you can enhance the original file replacing the if-else assignment with an expanded if-else block of code before running it through coverage (as if the variable assignment where syntactic sugar). It's beyond my comprehension the difficulty of such an "enhancement operator".

  4. Log in to comment