473,320 Members | 2,158 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

doctest not seeing any of my doc tests

I have a function in my module:

def selftest(verbose=False):
import doctest
doctest.testmod(verbose=verbose)
When I run it, it fails to find any of my doc tests, including the tests
in __main__, and in fact it looks like it can't even find my functions
and classes:

>>mymodule.selftest(True)
1 items had no tests:
__main__
0 tests in 1 items.
0 passed and 0 failed.
Test passed.
The second and subsequent times I call selftest, I get the same result
except that it adds this line to the end:

*** DocTestRunner.merge: '__main__' in both testers; summing outcomes.
I've exited from Python and restarted the interactive interpreter. I've
deleted the module .pyc file. Neither has helped.

I've tried reading over the doctest module to see if there are any hints
as to what's going wrong, but it's quite opaque to me. If there's anyone
out there with a good understanding of doctest, I'd appreciate some
pointers for where to start looking, or otherwise how to fix this problem.

For what it's worth, I'm running

Python 2.5 (r25:51908, Apr 10 2007, 10:29:13)
[GCC 4.1.2 20070403 (Red Hat 4.1.2-8)] on linux2


--
Steven
Sep 7 '08 #1
3 1093
Steven D'Aprano wrote:
I have a function in my module:

def selftest(verbose=False):
import doctest
doctest.testmod(verbose=verbose)
what happens if you change the above to

def selftest(verbose=False):
import doctest, yourmodule
doctest.testmod(yourmodule, verbose=verbose)

(where yourmodule is the name of your module, obviously)

</F>

Sep 7 '08 #2
Steven D'Aprano, first of all you can try to run a minimal module, to
see if your doctesting works, like:

"""
>>1 + 1
3
"""
def foo():
"""
>>foo()
1
"""
return 0
import doctest
doctest.testmod()

If that works correctly, then you can show us some more of the code
and tests.

Bye,
bearophile
Sep 7 '08 #3
On Sun, 07 Sep 2008 15:51:01 +0200, Fredrik Lundh wrote:
Steven D'Aprano wrote:
>I have a function in my module:

def selftest(verbose=False):
import doctest
doctest.testmod(verbose=verbose)

what happens if you change the above to

def selftest(verbose=False):
import doctest, yourmodule
doctest.testmod(yourmodule, verbose=verbose)

(where yourmodule is the name of your module, obviously)


Well, that certainly fixed the problem, thanks. It now correctly runs all
my doctests.

But I don't understand why a bare doctest.testmod() works when you run it
non-interactively, but fails when run interactively.

--
Steven
Sep 7 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Thomas Heller | last post by:
I've just read the 'Automating testing with doctest' pycon paper, and I'm exited about the future of doctest. This simple script reads the ctypes docs written in StructuredText, and runs and...
2
by: Alan G Isaac | last post by:
> python doctest.py -v Running doctest.__doc__ Trying: .remove(42) Expecting: Traceback (most recent call last): File "<stdin>", line 1, in ? ValueError: list.remove(x): x not in list ok...
2
by: Michele Simionato | last post by:
Some time ago I hacked a custom solution to run doctests on text files containing documentation. The solution involved this kind of game: tester=doctest.Tester(globs={},verbose=1)...
24
by: john_sips_tea | last post by:
For writing testcode, it looks like there's three ways that it's typically done: (1). using the doctest module, (2). using the unittest module (i.e. "pyunit"), or else (3). just putting an...
0
by: Steven Bethard | last post by:
I have an optparse-like module and though I have a full unittest-style suite of tests for it, I'd also like to be able to run doctest on the documentation to make sure my examples all work. ...
0
by: davidlmontgomery | last post by:
I'm trying to use both nosetests and doctest with the tests pulled out into a separate file. My problem is that it seems that I need to use different import statements depending on from where I...
6
by: Bzyczek | last post by:
Hello, I have problems with running doctests if I use czech national characters in UTF-8 encoding. I have Python script, which begin with encoding definition: # -*- coding: utf-8 -*- I...
4
by: petr.jakes.tpc | last post by:
Hi, inspired by the article written by Tarek Ziade in the February 07 issue of the "Linux +" magazine I am experimenting with the doctest module. I have two files, "displeje_pokus.py" and...
2
by: mde | last post by:
I'm wondering if there is a "best practice" for *creating doctests in methods* that reduces clutter/duplication of dummy instantiations. In the following code there are five (labeled 1-5) possible...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.