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

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 2291
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
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
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*******@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
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

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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
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...
38
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...
72
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: ...
6
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...
27
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...
5
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...
0
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...
4
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...
10
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...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
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: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
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: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.