Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
nedbat opened this issue Sep 18, 2017 · 4 comments
Closed
Labels
branch duplicate This issue or pull request already exists enhancement New feature or request

Comments

@nedbat
Copy link
Owner

nedbat commented Sep 18, 2017

Originally reported by Federico Carrá (Bitbucket: feferulo, GitHub: Unknown)


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

#!python


variable = 1 if some_condition else -1

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


@nedbat
Copy link
Owner Author

nedbat commented Sep 21, 2017

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 coverage.py will need significant changes to make use of it.

@nedbat
Copy link
Owner Author

nedbat commented Feb 7, 2018

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

@nedbat
Copy link
Owner Author

nedbat commented Feb 22, 2018

Original comment by Federico Carrá (Bitbucket: feferulo, GitHub: Unknown)


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".

@nedbat nedbat added major enhancement New feature or request labels Jun 23, 2018
@nedbat nedbat removed the 4.4 label Aug 17, 2018
@nedbat nedbat added branch and removed major labels Jan 15, 2020
@ngie-eign
Copy link

This is a duplicate of #509.

@nedbat nedbat added the duplicate This issue or pull request already exists label Feb 24, 2021
@nedbat nedbat closed this as completed Feb 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
branch duplicate This issue or pull request already exists enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants