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

Multiline asserts need too many pragma: no covers #461

Closed
nedbat opened this issue Jan 3, 2016 · 10 comments
Closed

Multiline asserts need too many pragma: no covers #461

nedbat opened this issue Jan 3, 2016 · 10 comments
Labels
bug Something isn't working

Comments

@nedbat
Copy link
Owner

nedbat commented Jan 3, 2016

Originally reported by Barry Warsaw (Bitbucket: warsaw, GitHub: warsaw)


Code like the following:

#!python

        assert command_class.name not in config.commands, (  # pragma: no cover
            'Duplicate email command "{}" found in {}'.format( # pragma: no cover
                command_class.name,                            # pragma: no cover
                command_class.__module__))

Note the pragma: no cover on every line. I want to completely ignore the entire assert statement, but w/o all those pragmas, I get a report that some of those lines aren't covered, which is true, but unhelpful!


@nedbat
Copy link
Owner Author

nedbat commented Jan 3, 2016

@warsaw can you provide a complete runnable example? Is the statement not covered because of -O?

@nedbat
Copy link
Owner Author

nedbat commented Jan 3, 2016

This was my attempt to reproduce it:

$ cat bug461.py
a = 1
assert not a, (
      'Duplicate email command "{}" found in {}'.format(
                len([]),
                len([1])))
b = 2
print(a, b)
$ PYTHONOPTIMIZE=1 coverage run bug461.py
(1, 2)
$ coverage report -m
Name        Stmts   Miss  Cover   Missing
-----------------------------------------
bug461.py       4      1    75%   2
$ vim bug461.py
$ cat bug461.py
a = 1
assert not a, (                                             # pragma: no cover
      'Duplicate email command "{}" found in {}'.format(
                len([]),
                len([1])))
b = 2
print(a, b)
$ PYTHONOPTIMIZE=1 coverage run bug461.py
(1, 2)
$ coverage report -m
Name        Stmts   Miss  Cover   Missing
-----------------------------------------
bug461.py       3      0   100%

Here only line 2 is considered a statement, and a single pragma was enough to quiet it.

@nedbat
Copy link
Owner Author

nedbat commented Jan 3, 2016

Original comment by Barry Warsaw (Bitbucket: warsaw, GitHub: warsaw)


That's interesting. In my larger test case, I'm not running with -O, and it seems like all four lines in the assert are being counted (and thus all four need pragma: no cover). I'll have to see if I can boil down to a smaller reproducible test case.

@nedbat
Copy link
Owner Author

nedbat commented Jan 3, 2016

If it doesn't reduce down, you can give me instructions how to run the larger test case.

@nedbat
Copy link
Owner Author

nedbat commented Jan 4, 2016

Original comment by Barry Warsaw (Bitbucket: warsaw, GitHub: warsaw)


Hi Ned, thanks for the help. You should be able to reproduce like so:

#!

$ git clone https://gitlab.com/mailman/mailman.git
$ cd mailman
$ tox -e coverage

You might have to change basepython to python3.4 in tox.ini if you don't have Python 3.5. I'm fairly certain it's not a Python 3.4/3.5 thing, but I can check that.

There are several cases where multiline asserts are being treated as multiple statements and being reported as not covered. src/mailman/app/commands.py is a good example. Note that I tried # pragma: no cover on these lines, but the current git head uses an exclude_lines in coverage.ini, which the tox.ini arranges to be used.

@nedbat
Copy link
Owner Author

nedbat commented Jan 5, 2016

OK, I've reproduced your results in your repo, thanks. Now to figure out why it's different than my test case....

@nedbat
Copy link
Owner Author

nedbat commented Jan 5, 2016

Turns out this is another instance of http://bugs.python.org/issue19035: form-feeds look like end-of-file. @warsaw is it possible you are the only person still using form-feeds? :) :)

I'll make a fix soon.

@nedbat
Copy link
Owner Author

nedbat commented Jan 5, 2016

Original comment by Barry Warsaw (Bitbucket: warsaw, GitHub: warsaw)


Oh gosh. Too funny, and yeah probably so! I really should get rid of those, but it's a lot of legacy code to go through. Thanks for working on the fix! (I should take a crack at the Python bug.)

@nedbat
Copy link
Owner Author

nedbat commented Jan 5, 2016

Fixed in b3a775b34648 (bb), which will be in 4.1.

@nedbat
Copy link
Owner Author

nedbat commented Jan 6, 2016

Original comment by Barry Warsaw (Bitbucket: warsaw, GitHub: warsaw)


Thanks!

@nedbat nedbat closed this as completed Jan 6, 2016
@nedbat nedbat added major bug Something isn't working labels Jun 23, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant