473,568 Members | 2,850 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Unit Testing in Python

Hi Everyone,
I've recently been reading some articles about unit-testing in Python
[1] [2], but I am a bit confused: where do I go to get started with
this? I tried googling for "unittest" but all I've found are some old
links to projects that already use it, and the older (as the articles
put it) PyUnit project. I'm sorry if this is a obvious question or one
that has already been answered, but unit-testing sounds interesting and
I'm not sure where to start.

Thanks,
Ryan Kaulakis

Jul 18 '05 #1
11 2314
In article <11************ **********@o13g 2000cwo.googleg roups.com>,
"rhat" <fa*******@gmai l.com> wrote:
Hi Everyone,
I've recently been reading some articles about unit-testing in Python
[1] [2], but I am a bit confused: where do I go to get started with
this? I tried googling for "unittest" but all I've found are some old
links to projects that already use it, and the older (as the articles
put it) PyUnit project. I'm sorry if this is a obvious question or one
that has already been answered, but unit-testing sounds interesting and
I'm not sure where to start.

Thanks,
Ryan Kaulakis


PyUnit is indeed what I use. It's included in current distributions as the
"unittest" module.

The module docs aren't perfect (especially when it comes to the big
picture), but there's a good tutorial at
http://diveintopython.org/unit_testing/index.html

Once you get your head around how it works, it's really quite simple to
use. It also has the advantage of being one of a series of "X-unit"
packages for different languages (Junit, C++Unit, etc) which all have the
same organization (with allowances made for language-specific
requirements). This means once you've learned one, you've got a big head
start one learning another one.
Jul 18 '05 #2
Neat the original poster shows up as a potential Phisher with a nice
big red warning in gmail.

Due to some funky header fakedness.

Don't give them your SSN. :)

I have a related question. What is PyDoc? I see it come up alot in
searches for Unit testing and python, but I've never gotten around to
finding out why.
Maybe I'll do that now.

On Thu, 10 Feb 2005 21:34:06 -0500, Roy Smith <ro*@panix.co m> wrote:
In article <11************ **********@o13g 2000cwo.googleg roups.com>,
"rhat" <fa*******@gmai l.com> wrote:
Hi Everyone,
I've recently been reading some articles about unit-testing in Python
[1] [2], but I am a bit confused: where do I go to get started with
this? I tried googling for "unittest" but all I've found are some old
links to projects that already use it, and the older (as the articles
put it) PyUnit project. I'm sorry if this is a obvious question or one
that has already been answered, but unit-testing sounds interesting and
I'm not sure where to start.

Thanks,
Ryan Kaulakis


PyUnit is indeed what I use. It's included in current distributions as the
"unittest" module.

The module docs aren't perfect (especially when it comes to the big
picture), but there's a good tutorial at
http://diveintopython.org/unit_testing/index.html

Once you get your head around how it works, it's really quite simple to
use. It also has the advantage of being one of a series of "X-unit"
packages for different languages (Junit, C++Unit, etc) which all have the
same organization (with allowances made for language-specific
requirements). This means once you've learned one, you've got a big head
start one learning another one.
--
http://mail.python.org/mailman/listinfo/python-list

--
Thomas G. Willis
http://paperbackmusic.net
Jul 18 '05 #3
Yeah, you know I only ask questions about Test-driven development
basics in hopes of obtaining your personal information, so that I can
sell it on the Molodovian blackmarket. I'm not a "Phisher", I'm a
comp-sci major who's too lazy to dig around for his own answers. ;)

Thanks for your help Roy, I wasn't sure what the difference between
unittest and pyunit were.
--|2 \| /-\ |\| |</-\|_||_/-\|<15 (the uber-l33t version of my
supersecret "phishing" alias which just so happens to be my actual
name)

PS: Yeah, I too am plerplexed as to why gmail allowed me to register
"fakeadmin" as a login. Sure makes a good conversation started though.
=P

Jul 18 '05 #4
It could be a bug in gmail. I wasn't actually accusing you, just
thought it was funny enough to point out. Of course you could be more
sarcastic than me who knows. :)

I'm not worried though. I believe the best strategy against Identity
theft is bad credit.

So question , do you see the big red block on your own posts, or have
I been sitting in front of the puter too long?
On Thu, 10 Feb 2005 19:25:13 -0800 (PST), rhat <fa*******@gmai l.com> wrote:
Yeah, you know I only ask questions about Test-driven development
basics in hopes of obtaining your personal information, so that I can
sell it on the Molodovian blackmarket. I'm not a "Phisher", I'm a
comp-sci major who's too lazy to dig around for his own answers. ;)

Thanks for your help Roy, I wasn't sure what the difference between
unittest and pyunit were.
--|2 \| /-\ |\| |</-\|_||_/-\|<15 (the uber-l33t version of my
supersecret "phishing" alias which just so happens to be my actual
name)

PS: Yeah, I too am plerplexed as to why gmail allowed me to register
"fakeadmin" as a login. Sure makes a good conversation started though.
=P

--
http://mail.python.org/mailman/listinfo/python-list

--
Thomas G. Willis
http://paperbackmusic.net
Jul 18 '05 #5
rhat said unto the world upon 2005-02-10 21:10:
Hi Everyone,
I've recently been reading some articles about unit-testing in Python
[1] [2], but I am a bit confused: where do I go to get started with
this? I tried googling for "unittest" but all I've found are some old
links to projects that already use it, and the older (as the articles
put it) PyUnit project. I'm sorry if this is a obvious question or one
that has already been answered, but unit-testing sounds interesting and
I'm not sure where to start.

Thanks,
Ryan Kaulakis


Hi,

I've just started learning about testing and TDD, but I found the
following recent articles and blog posts useful:

<http://agiletesting.bl ogspot.com/2005/01/python-unit-testing-part-1-unittest.html>
<http://agiletesting.bl ogspot.com/2005/01/python-unit-testing-part-2-doctest.html>
<http://agiletesting.bl ogspot.com/2005/01/python-unit-testing-part-3-pytest-tool.html>
<http://www.onlamp.com/lpt/a/5463>
<http://www.onlamp.com/lpt/a/5584>

(Your footnotes didn't come through, so these might not be new to you.)

Best,

Brian vdB

Jul 18 '05 #6

Tom Willis wrote:
It could be a bug in gmail. I wasn't actually accusing you, just
thought it was funny enough to point out. Of course you could be more
sarcastic than me who knows. :)

I'm not worried though. I believe the best strategy against Identity
theft is bad credit.

So question , do you see the big red block on your own posts, or have
I been sitting in front of the puter too long?
On Thu, 10 Feb 2005 19:25:13 -0800 (PST), rhat <fa*******@gmai l.com>

wrote:
Yeah, you know I only ask questions about Test-driven development
basics in hopes of obtaining your personal information, so that I can sell it on the Molodovian blackmarket. I'm not a "Phisher", I'm a
comp-sci major who's too lazy to dig around for his own answers. ;)

Thanks for your help Roy, I wasn't sure what the difference between
unittest and pyunit were.
--|2 \| /-\ |\| |</-\|_||_/-\|<15 (the uber-l33t version of my
supersecret "phishing" alias which just so happens to be my actual
name)

PS: Yeah, I too am plerplexed as to why gmail allowed me to register "fakeadmin" as a login. Sure makes a good conversation started though. =P

--
http://mail.python.org/mailman/listinfo/python-list

--
Thomas G. Willis
http://paperbackmusic.net


I'm glad people have a still have a sense of humor, and yes gmail does
flag mail that I send myself (as in fa*******@gmail .com ->
fa*******@gmail .com) as being possibly "not from who they claim" I
don't have any other gmail accounts, so I just thought it happened with
all accounts.

Jul 18 '05 #7
I actually meant to link to the last two ONLamp articles you mentioned,
so yeah I have seen those (kinda forgot to post them, in fact). Thanks
for the other links too, they look pretty interesting.
Incidentally, what kind of projects are you guys (planning on) using
this technology with? I'm working on educational software, and thought
that it might be neat to try unittest out on. Though, in truth, I don't
know enough about unit-testing to make a design decision that large
yet.

Feel free to [reply | flame the n00b],
Ryan Kaulakis

Jul 18 '05 #8
> put it) PyUnit project. I'm sorry if this is a obvious question or one
that has already been answered, but unit-testing sounds interesting and
I'm not sure where to start.


Hi Ryan. I belive this (http://www.xp123.com/xplor/xp0201/index.shtml)
is a good way to learn about unit testing by practice if you already
know the basics of it. It is written in Java but is easy to translate
to Python. Unittesting really is great in Python, I try to use it for
anything but simple and dirty hacks.

--
mvh Björn
Jul 18 '05 #9
I've had great experience doing Test Driven Development. Ideally you
would do it from the start, but it is great for refactoring as well.
In any language.

One of the pitfalls to look out for is to not get too hung up on it.
In the end it's just a tool you use at your discretion. When I first
started doing it, I would get hung up on how the test framework should
look etc... almost as if I was architecting a system. It really slowed
me down.

I now take this approach...

1. what is the smallest piece of functionality that I want? (What to test)
2. what test will confirm I have this functionality?( How to test it)
3. how will I access this functionality.( Define the API)
4. write test
5. write code
6. run test.
7. repeat 4,5,6 until you're happy.

Frameworks like xUnit etc... just enhance the experience but are in no
way required in my opinion.

Another nice side effect is that your architecture design then comes
naturally and it is exactly what you need nothing more, nothing less.

I recently converted a very problematic data migration routine that
was written in Transact SQL by a consultant who liked to push the
limits of their chosen tool.

I wrote it in Python because I was predicting that no one could nail
down all the possible permutations of data that might come through. I
needed the ability for the routine to be flexible.

Anywho, using python and TDD I was able to get functionality
running/tested from minute 1 using only XEmacs and ipython.

On Fri, 11 Feb 2005 12:39:07 +0100, BJörn Lindqvist <bj*****@gmail. com> wrote:
put it) PyUnit project. I'm sorry if this is a obvious question or one
that has already been answered, but unit-testing sounds interesting and
I'm not sure where to start.


Hi Ryan. I belive this (http://www.xp123.com/xplor/xp0201/index.shtml)
is a good way to learn about unit testing by practice if you already
know the basics of it. It is written in Java but is easy to translate
to Python. Unittesting really is great in Python, I try to use it for
anything but simple and dirty hacks.

--
mvh Björn
--
http://mail.python.org/mailman/listinfo/python-list

--
Thomas G. Willis
http://paperbackmusic.net
Jul 18 '05 #10

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

Similar topics

6
3676
by: Tom Verbeure | last post by:
Hello All, so I'm now convinced that unit testing is really the way to go and I want to add it to an existing project. The first thing that I find out, is that, well, it's hard work. Harder than writing the real functional code. My application manipulates graphs. I first write the skeleton in Python, then convert it to C++ for high...
38
3373
by: Christoph Zwerschke | last post by:
In August 2001, there was a thread about the "Art of Unit Testing": http://groups.google.com/group/comp.lang.python/browse_frm/thread/aa2bd17e7f995d05/71a29faf0a0485d5 Paul Moore asked the legitimate question why there is no hook for a "global" fixture code that is run only once for the whole TestCase, as opposed to the normal "setUp" and...
72
5188
by: Jacob | last post by:
I have compiled a set og unit testing recommendations based on my own experience on the concept. Feedback and suggestions for improvements are appreciated: http://geosoft.no/development/unittesting.html Thanks.
6
5676
by: Vyacheslav Maslov | last post by:
Hi all! I have many many many python unit test, which are used for testing some remote web service. The most important issue here is logging of test execution process and result. I strongly need following: 1. start/end timestamp for each test case (most important) 2. immediate report about exceptions (stacktrace) 3. it will be nice to...
27
2527
by: brad | last post by:
Does anyone else feel that unittesting is too much work? Not in general, just the official unittest module for small to medium sized projects? It seems easier to write some quick methods that are used when needed rather than building a program with integrated unittesting. I see the value of it (the official unittest that is)... especially...
5
2233
by: Ben Finney | last post by:
Howdy all, PEP 299 <URL:http://www.python.org/dev/peps/pep-0299details an enhancement for entry points to Python programs: a module attribute (named '__main__') that will be automatically called if the module is run as a program. The PEP has status "Rejected", citing backward-compatibility issues, and Guido's pronouncement that "It's not...
0
1281
by: Bryan Berry | last post by:
I manage a team of 5 linux sysadmins and I am trying to transition us from lengthy, mostly unreadable shell scripts to python scripting. After a few tutorials, I have been infected with the unit testing bug. Our scripts create custom versions of Fedora Core, build and deploy web software, and test servers post-installation for proper...
4
1134
by: Emanuele D'Arrigo | last post by:
Hi everybody, I'm just having a go with Unit Testing for the first time and my feeling about it in short is: Neat! I'm a bit worried about the time it's taking me to develop the tests but after only a day or so I'm already much faster than when I started with it and the code is already much improved in terms of robustness. A couple of...
10
3903
by: Brendan Miller | last post by:
What would heavy python unit testers say is the best framework? I've seen a few mentions that maybe the built in unittest framework isn't that great. I've heard a couple of good things about py.test and nose. Are there other options? Is there any kind of concensus about the best, or at least how they stack up to each other? Brendan
0
7693
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
1
7660
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...
0
7962
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6275
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...
0
5217
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3631
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2101
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
1
1207
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
932
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...

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.