Yielded twisted failure marked as missed

Issue #440 resolved
Jakob de Maeyer
created an issue

Hi,

in this except clause (lines 75 through 81), we catch all exceptions, do some cleanup, and then reraise the exception by wrapping it in a twisted.Failure. The whole function is wrapped inside twisted's inlineCallbacks magic.

The coverage report (XML here, run with timid = True) shows the variable assignment in line 80 being hit but the subsequent line being missed. An accompanying test passes when line 81 is there and fails when I remove it, so I'm pretty sure it should indeed be hit.

I tried to create a minimal working example here but failed, sorry :/

Comments (8)

  1. Jakob de Maeyer reporter

    Hey Ned, thanks for looking into it.

    I'm afraid I'm not too familiar with the test suite internals. I clone the repository, then run tox2 in it, or tox2 -- tests/test_crawl.py::CrawlTestCase::test_graceful_crawl_error_handling to run the relevant test only, after enabling timid mode in .coveragerc.

    btw I use coverage.py every day, also good stuff :)

  2. Ned Batchelder repo owner

    @Jakob de Maeyer Looks like this is a really simple thing that doesn't involve Twisted at all. I didn't understand your smaller test cases that didn't work. I think this boils down to: yields that are never returned to are marked as not executed:

    $ cat foo.py
    def gen():
        print("yup")
        yield "yielded"
        print("nope")
    
    print(next(gen()))
    $ coverage run --branch foo.py
    yup
    yielded
    $ coverage report -m
    Name     Stmts   Miss Branch BrPart  Cover   Missing
    ----------------------------------------------------
    foo.py       5      2      0      0    60%   3-4
    

    When run without branch coverage, it's understood better:

    $ coverage run foo.py
    yup
    yielded
    $ coverage report -m
    Name     Stmts   Miss  Cover   Missing
    --------------------------------------
    foo.py       5      1    80%   4
    
  3. Log in to comment