473,770 Members | 7,142 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Running doctests with unittest

I'm trying to integrate some doctest tests with unittest. The tests
must be exposed as one or more subclasses of unittest.TestCa se, so I'm
collecting them with a call to doctest.DocTest Suite(), and then add them
to a TestCase class I have created.
The tests seem to run, but they always seem to succeed - I have no idea
why. Any ideas?

Thomas

---snip---
"""
print "Hi"
print 1213 """

def func():
""" print "spam"
print blah

"""

import doctest, unittest
suite = doctest.DocTest Suite()

class TestCase(unitte st.TestCase):
pass

for index, test in enumerate(suite ._tests):
setattr(TestCas e, "test_%d" % index, test)

if __name__ == "__main__":
if 1:
import unittest
unittest.main()
else:
import doctest
doctest.testmod ()
---snip---
Jul 18 '05 #1
1 1510
Thomas Heller wrote:
I'm trying to integrate some doctest tests with unittest. The tests
must be exposed as one or more subclasses of unittest.TestCa se, so I'm
collecting them with a call to doctest.DocTest Suite(), and then add them
to a TestCase class I have created.
The tests seem to run, but they always seem to succeed - I have no idea
why. Any ideas?

Thomas

---snip---
"""
print "Hi"
print 1213
"""

def func():
""" >>> print "spam"
>>> print blah

"""

import doctest, unittest
suite = doctest.DocTest Suite()

class TestCase(unitte st.TestCase):
pass

for index, test in enumerate(suite ._tests):
setattr(TestCas e, "test_%d" % index, test)

if __name__ == "__main__":
if 1:
import unittest
unittest.main()
else:
import doctest
doctest.testmod ()
---snip---


I can't explain why all the tests seemed to pass, but I tried a
different approach that works.

Once you have a suite object, you just need to run it. The
TextTestRunner works well for that. I got output errors and failures by
doing the following:

if __name__ == '__main__':
import doctest, unittest
suite = doctest.DocTest Suite()
testRunner = unittest.TextTe stRunner()
testRunner.run( suite)

HTH,
Jim Sizelove
Jul 18 '05 #2

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

Similar topics

5
2316
by: Will Stuyvesant | last post by:
I have a unittest testfile like this: ----------------------- test_mod.py --------------------- import sys sys.path.append('..') import unittest import mod class Test_rmlutils(unittest.TestCase):
0
1289
by: Danny Shevitz | last post by:
Why doesn't the following code snippet work? The error is ImportError: No module named myTestCase2 TIA, Danny %<--------------------------------------------------------------------
0
2054
by: Remy Blank | last post by:
Ok, here we go. I added the possibility for tests using the unittest.py framework to be skipped. Basically, I added two methods to TestCase: TestCase.skip(msg): skips unconditionally TestCase.skipIf(expr, msg): skips if expr is true These can be called either in setUp() or in the test methods. I also added reporting of skipped tests to TestResult, _TextTestResult and
41
10295
by: Roy Smith | last post by:
I've used the standard unittest (pyunit) module on a few projects in the past and have always thought it basicly worked fine but was just a little too complicated for what it did. I'm starting a new project now and I'm thinking of trying py.test (http://codespeak.net/py/current/doc/test.html). It looks pretty cool from the docs. Is there anybody out there who has used both packages and can give a comparative review?
7
2073
by: Jorgen Grahn | last post by:
I have a set of tests in different modules: test_foo.py, test_bar.py and so on. All of these use the simplest possible internal layout: a number of classes containing test*() methods, and the good old lines at the end: if __name__ == "__main__": unittest.main() This is great, because each of the modules are runnable, and I can select classes or tests to run on the commandline if I want to. However, running all the tests from e.g. a...
3
3435
by: David Vincent | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hello I'm hoping to get some insight into a situation that seems odd to me. My Python experience is limited; I've just started using the unittest module. I've had some experience with unit test support in other languages.
3
1358
by: notanotheridiot | last post by:
Hi, I have two strings - a docstring containing doctests and a code string containing code to be tested with those doctests. I've been trying for a day now to run the test without concatenating the two strings, adding: import doctest doctest.testmod to the bottom, writing it all to a file and executing it using popen().
1
3941
by: Chris Fonnesbeck | last post by:
I have a module for which I am trying to code a unit test. However, when I run unittest.main(), I get: In : import PyMC In : PyMC.unittest.main() ---------------------------------------------------------------------- Ran 0 tests in 0.000s
0
990
by: =?ISO-8859-1?Q?Israel_Fern=E1ndez_Cabrera?= | last post by:
Hi I'm writing some code that automatically execute some registered unit test in a way to automate the process. A sample code follows to illustrate what I'm doing: <code requires="save as import_tests.py"> class PruebasDePrueba(unittest.TestCase): def testUnTest(self): a = 2 b = 1
0
9425
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10058
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10004
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8886
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5313
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5450
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3972
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3576
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2817
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.