Git Product home page Git Product logo

Comments (8)

nedbat avatar nedbat commented on June 14, 2024

Removing version: 3.0.1 (automated comment)

from coveragepy.

nedbat avatar nedbat commented on June 14, 2024

One last interesting detail: nose monkeypatches doctest, so even on Python 2.4, if you use nose to run your tests, all your code will be covered.

from coveragepy.

nedbat avatar nedbat commented on June 14, 2024

For completeness: it seems that this flaw was introduced in Python 2.4 and fixed in Python 2.5, so only Python 2.4 is affected.

from coveragepy.

nedbat avatar nedbat commented on June 14, 2024

This is a flaw in doctest that was fixed in Python 2.5. If you need to, you can patch doctest.py yourself with this patch: http://svn.zope.org/Zope3/trunk/src/zope/testing/doctest.py?rev=28679&r1=28703&r2=28705

from coveragepy.

nedbat avatar nedbat commented on June 14, 2024

Original comment by Anonymous


Hello Dears,

First of all, thanks Ned for your coverage tool.

I have made a simple example for you that is using doctests. The results shown by coverage are not ok unfortunately:

check_doctest_coverage.py:

#!python

def return_arg_or_void(arg):
  """If <arg> is None, return "Void"; otherwise return <arg>
  
  >>> return_arg_or_void(None)
  'Void'
  >>> return_arg_or_void("arg")
  'arg'
  >>> return_arg_or_void("None")
  'None'
  """
  if arg is None:
    return "Void"
  else:
    return arg
  
if __name__ == "__main__":
  import doctest
  doctest.testmod()

When you run python check_doctest_coverage.py -v

Trying:
    return_arg_or_void(None)
Expecting:
    'Void'
ok
Trying:
    return_arg_or_void("arg")
Expecting:
    'arg'
ok
Trying:
    return_arg_or_void("None")
Expecting:
    'None'
ok
1 items had no tests:
    __main__
1 items passed all tests:
   3 tests in __main__.return_arg_or_void
3 tests in 2 items.
3 passed and 0 failed.
Test passed.

When you annotate the file with coverage annotate -d res check_doctest_coverage.py

> def return_arg_or_void(arg):
>   """If <arg> is None, return "Void"; otherwise return <arg>
    
>   >>> return_arg_or_void(None)
>   'Void'
>   >>> return_arg_or_void("arg")
>   'arg'
>   >>> return_arg_or_void("None")
>   'None'
>   """
>   if arg is None:
>     return "Void"
!   else:
!     return arg
    
> if __name__ == "__main__":
>   import doctest
>   doctest.testmod()

So the else part is reported as not executed, although it is (the run of doctest reported 3 successful tests)

Kind regards,

-- Frederic F. M

from coveragepy.

nedbat avatar nedbat commented on June 14, 2024

Do you have an example I can use? I don't use doctests myself, so it's very likely I've overlooked something.

from coveragepy.

nedbat avatar nedbat commented on June 14, 2024

Original comment by Larry Gilbert (Bitbucket: l2g, GitHub: l2g)


You're right, it wouldn't make sense to expect the doctest lines themselves to show up as covered.

The problem I encountered was that lines of code tested //with// doctest were not being highlighted correctly. I will try to work up an example for you.

Incidentally, I've been trying out nose for tests, which as you probably know uses coverage.py for its coverage reports. nosetests has an option to include doctest test runs when calculating covered code. This did what I expected in the first place. So maybe I am expecting it to be coverage.py's job when it really is up to something like nose. I'm still a rookie at all of this. :-)

from coveragepy.

nedbat avatar nedbat commented on June 14, 2024

If I understand what you mean, coverage.py won't indentify the lines in the doctests as executable. This is because they aren't executable: it's the doctest module that pre-processes the docstring and executes it.

Or do you mean that your product code executed by doctests is not identified as executed?

If the first, I wouldn't have thought this would be a problem, since doctests don't typically include conditionals that would make coverage testing important.

If the latter, please provide a small code sample.

from coveragepy.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.