By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,224 Members | 1,120 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,224 IT Pros & Developers. It's quick & easy.

Unit Testing in Python

P: n/a
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
Share this Question
Share on Google+
11 Replies


P: n/a
In article <11**********************@o13g2000cwo.googlegroups .com>,
"rhat" <fa*******@gmail.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

P: n/a
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.com> wrote:
In article <11**********************@o13g2000cwo.googlegroups .com>,
"rhat" <fa*******@gmail.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

P: n/a
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

P: n/a
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*******@gmail.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

P: n/a
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.blogspot.com/2005/01/python-unit-testing-part-1-unittest.html>
<http://agiletesting.blogspot.com/2005/01/python-unit-testing-part-2-doctest.html>
<http://agiletesting.blogspot.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

P: n/a

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*******@gmail.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

P: n/a
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

P: n/a
> 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

P: n/a
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

P: n/a
A great place to start for TDD-related stuff is testdriven.com. On the
topic of Python-specific unit testing, there's also a recent thread on
the newly-created extreme-python google group:
http://groups-beta.google.com/group/...cf6c844f?tvc=2

Grig

====
http://agiletesting.blogspot.com

Jul 18 '05 #11

P: n/a
No-nonsense PyUnit skeleton: http://www.python.org/moin/PyUnit

Copy & Paste.

Though there's a new module,
[http://codespeak.net/py/current/doc/test.html py.test,] that's easier
in many ways.

Jul 18 '05 #12

This discussion thread is closed

Replies have been disabled for this discussion.