Skip to content
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

Lambda expression confuses branch measurement #90

Closed
nedbat opened this issue Sep 12, 2010 · 9 comments
Closed

Lambda expression confuses branch measurement #90

nedbat opened this issue Sep 12, 2010 · 9 comments
Labels
branch bug Something isn't working

Comments

@nedbat
Copy link
Owner

nedbat commented Sep 12, 2010

A line like this:

    fn = make_sortable or (lambda x: x) 

is marked as being a branch with a missing jump to "exit", maybe only if the lambda isn't used.


@nedbat
Copy link
Owner Author

nedbat commented May 27, 2011

Original comment by Carl Meyer (Bitbucket: carljm, GitHub: carljm)


I can verify that, at least in my case, the missing jump to exit disappeared when I ensured the lambda was used during the test run. Seems to me this could be considered useful coverage information, not a bug -- if anything, the branch-coverage report should special-case this to display a more informative label on the line?

@nedbat
Copy link
Owner Author

nedbat commented Jan 15, 2013

A particularly confusing form of this bug:

OPERATIONS = [
    operator.add,
    operator.sub,
    lambda x: 2*x,
    operator.mul,
]

The "OPERATIONS = " line will have a missed branch to "exit" if the lambda expression is never executed.

@nedbat
Copy link
Owner Author

nedbat commented Jan 2, 2016

Bug #460 is related to this.

@nedbat
Copy link
Owner Author

nedbat commented Jan 6, 2016

Perhaps the best we can do here is to report it as "Missed lambda" instead of "missed branch to exit."

@nedbat
Copy link
Owner Author

nedbat commented May 7, 2016

It's not as good as I would like, but as of now, the HTML shows "3 ↛ exit", and the hover text reads "line 6 didn't finish the lambda on line 6".

I think this provides enough information to the reader. Getting more precise would require collecting data differently, to distinguish the line 6 execution during building the list, from line 6 execution during running the lambda. We can distinguish them based on the co_firstlineno of the frame, but we don't have a way to record that data as we go.

@nedbat
Copy link
Owner Author

nedbat commented Aug 30, 2017

Original comment by Daniel Hahler (Bitbucket: blueyed, GitHub: blueyed)


Could this be reflected in the xml report, too?

@nedbat nedbat closed this as completed Aug 30, 2017
@nedbat nedbat added major bug Something isn't working branch labels Jun 23, 2018
agronholm pushed a commit to agronholm/coveragepy that referenced this issue Aug 16, 2020
@sigma67
Copy link

sigma67 commented Jun 15, 2023

Has this been fixed? I'm still seeing issues.

conversion_lookup: Dict[Type[Union[int, bool, float, str, Path]], Callable[[Any], str]] = {
        int: str,
        bool: str,
        float: str,
        str: str,
        Path: lambda x: str(x.as_posix()),
    }

coverage 7.2.7

@nedbat
Copy link
Owner Author

nedbat commented Jun 15, 2023

@sigma67 since this ticket is so old, it would be better to open a new issue with complete details of what the problem is and how to reproduce it.

@sigma67
Copy link

sigma67 commented Jun 15, 2023

The issue was actually on my end, the lambda function in question was in fact not covered. Sorry for bothering you about it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
branch bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants