473,405 Members | 2,279 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,405 software developers and data experts.

How to doctest if __name__ already used?

I have a simple question (I hope), but one I'd love to get some
feedback on in case I am missing something obvious:

If I have a Python script that is executable, and therefore
already uses '''if __name__ == "__main__"''' to call a function
of its own, what is then the easiest yet still most Pythonic way
to run doctest on the docstrings in the file?

Trigger doctest.testmod() via a "--test" command-line option, is
what I'm thinking. But is that really the best way?

--
Leo Breebaart <le*@lspace.org>
May 5 '06 #1
2 1248
On Fri, May 05, 2006 at 10:33:48PM +0000, Leo Breebaart wrote:
Trigger doctest.testmod() via a "--test" command-line option, is
what I'm thinking. But is that really the best way?

That is what I would have suggested.

-Chris
May 7 '06 #2

On May 5, 2006, at 10:33 PM, Leo Breebaart wrote:
I have a simple question (I hope), but one I'd love to get some
feedback on in case I am missing something obvious:

If I have a Python script that is executable, and therefore
already uses '''if __name__ == "__main__"''' to call a function
of its own, what is then the easiest yet still most Pythonic way
to run doctest on the docstrings in the file?

Trigger doctest.testmod() via a "--test" command-line option, is
what I'm thinking. But is that really the best way?


If it is just a single standalone script, then yeah, do it that way.
Once your program becomes a few files though, you might want a separate
"test" file that runs doctest.testmod on each of them.

Jay P.

May 7 '06 #3

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

Similar topics

14
by: Pierre Rouleau | last post by:
I have a problem writing self-testable modules using doctest when these modules have internationalized strings using gettext _('...'). - The main module of an application (say app.py) calls...
5
by: Michele Simionato | last post by:
I am getting a strange error with this script: $ cat doctest-threads.py """ >>> import time, threading >>> def example(): .... thread.out = .... while thread.running: .... ...
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...
1
by: Michael Tobis | last post by:
It appears that doctest does not work straightforwardly within iPython. I would like to be able to use doctest within a file conditionally, so that I can develop it within ipython and test it...
0
by: Leo | last post by:
Could someone please spare a .i file with an example doctest that works? I tried as follows and it fails: 1) I have an osi.i file that generates osi.py and _osi.so. At the very end I added:...
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...
3
by: Berthold Höllmann | last post by:
Saving the following code to a file and running the code through python does not give the expected error. disableling the "@decor" line leads to the expected error message. Is this a bug or an...
12
by: thomas.guest | last post by:
I'm not making progress with the following and would appreciate any help. Here's an interpreted Python session. .... Traceback (most recent call last): File "<stdin>", line 1, in <module>...
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.