472,345 Members | 1,519 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,345 software developers and data experts.

best python unit testing framwork

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
Nov 11 '08 #1
10 3767
Brendan Miller <ca******@catphive.netwrites:
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.
That's right, there are many flaws in ‘unittest’. It nevertheless has
the overwhelming advantage of being present in any standard Python
installation.

Using ‘nose’ at least builds upon the standard library ‘unittest’
module, so can easily integrate existing unit tests. It can also be
used as a unit test discovery and runner framework, which doesn't
impact the usefulness of the tests themselves on machines that don't
have ‘nose’ installed.

--
\ “Holy contributing to the delinquency of minors, Batman!” —Robin |
`\ |
_o__) |
Ben Finney
Nov 11 '08 #2
Brendan Miller <ca******@catphive.netwrites:
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
I find nose to be the best. It's simple, easy, and doesn't sacrifice
power. All good things if you value your time. :)
Nov 12 '08 #3
In article
<5f**********************************@d42g2000prb. googlegroups.com>,
Brendan Miller <ca******@catphive.netwrote:
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
I've been using unittest for years. I'm happy with it. I've looked at a
couple of the other ones (I don't remember exactly which ones) and came to
the conclusion that they didn't seem to provide enough advantage over
unittest to make it worth switching.

Just my opinion.
Nov 12 '08 #4
On Tue, Nov 11, 2008 at 2:59 PM, Brendan Miller <ca******@catphive.netwrote:
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
--
http://mail.python.org/mailman/listinfo/python-list
I wanted to like unittest but couldn't. So I started using py.test. I
even wrote a plugin for TextMate to interface with py.test. If I had
known about Nose I would likely have used it instead because it is
built on top of the standard module. Now I have many thousands of
lines of py.test code so am not likely to make the change.

--
Stand Fast,
tjg. [Timothy Grant]
Nov 12 '08 #5
In article <ma**************************************@python.o rg>,
"Timothy Grant" <ti***********@gmail.comwrote:
I wanted to like unittest but couldn't. So I started using py.test. I
even wrote a plugin for TextMate to interface with py.test. If I had
known about Nose I would likely have used it instead because it is
built on top of the standard module. Now I have many thousands of
lines of py.test code so am not likely to make the change.
A lot of people like or dislike various unit test frameworks for all sorts
of reasons. But, the bottom line is still that the best unit test
framework is the one which gets you to use it every time you write a line
of code.
Nov 13 '08 #6
On Wed, Nov 12, 2008 at 5:16 PM, Roy Smith <ro*@panix.comwrote:
In article <ma**************************************@python.o rg>,
"Timothy Grant" <ti***********@gmail.comwrote:
>I wanted to like unittest but couldn't. So I started using py.test. I
even wrote a plugin for TextMate to interface with py.test. If I had
known about Nose I would likely have used it instead because it is
built on top of the standard module. Now I have many thousands of
lines of py.test code so am not likely to make the change.

A lot of people like or dislike various unit test frameworks for all sorts
of reasons. But, the bottom line is still that the best unit test
framework is the one which gets you to use it every time you write a line
of code.
--
http://mail.python.org/mailman/listinfo/python-list
When I first learned about Unit Testing seven years ago, I thought to
myself "what a colossal waste of time." Now if I don't have tests I
really start to worry. I am a write the tests first kind-of-guy, and
my code and my ability to maintain my code have both improved
dramatically.
--
Stand Fast,
tjg. [Timothy Grant]
Nov 13 '08 #7
On 11 Nov, 22:59, Brendan Miller <catph...@catphive.netwrote:
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?
You don't mention what you want from testing so it's hard to say which
is "best" as it depends on one's point of view.

For example, I had a requirement to test more than just Python
programs. I wanted to test code written in any language. None of the
frameworks I found supported this so I wrote my own tester. It
interacts with programs via file streams - principally stdin, stdout
and stderr though others can be added as needed.

One nice by-product is that test code does not bloat-out the original
source which remains unchanged. And test cases can be written before,
alongside or after the code as desired.

So, YMMV.
--
James
Nov 13 '08 #8
On Thu, Nov 13, 2008 at 3:54 AM, James Harris
<ja************@googlemail.comwrote:
On 11 Nov, 22:59, Brendan Miller <catph...@catphive.netwrote:
>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?

You don't mention what you want from testing so it's hard to say which
is "best" as it depends on one's point of view.

For example, I had a requirement to test more than just Python
programs. I wanted to test code written in any language. None of the
frameworks I found supported this so I wrote my own tester. It
interacts with programs via file streams - principally stdin, stdout
and stderr though others can be added as needed.
I was speaking to unit tests (tests of individual classes and
functions in isolation of the rest of the program) and a test driven
development approach. I find those to be much more useful, and good
for pinpointing bugs and guiding development. In contrast regression
tests tend to be slow, and are the programmatic equivalent of kicking
the tires and seeing if they fall off.

I've also seen regression tests lead to a "sweep the bugs under the
rug mentality" where developers will code to prevent errors from
crashing the regression test, e.g. by catching and swallowing all
exceptions without fixing the underlying problem. It's easy to fool
regression tests since what it does works at such a high level that
most aspects of program correctness can't be directly checked. This is
very frustrating to me because it actually leads to lower code
quality.
>
One nice by-product is that test code does not bloat-out the original
source which remains unchanged.
That's the main reason most people don't write unit tests. It forces
them to properly decouple their code so that parts can be used
independently of one another. Adding such things to messy ball of mud
code after the fact is an enourmous pain in the butt. Thankfully,
since python is duck typed and doesn't require lots of boilerplate
writing interfaces and abstract factories (since the class object
itself acts as an abstract factory), writing properly decoupled code
in the first place doesn't look nearly as hard as in C++ or Java.
Nov 15 '08 #9
On 15 Nov, 01:02, "Brendan Miller" <catph...@catphive.netwrote:
On Thu, Nov 13, 2008 at 3:54 AM, James Harris

<james.harri...@googlemail.comwrote:
On 11 Nov, 22:59, Brendan Miller <catph...@catphive.netwrote:
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?
You don't mention what you want from testing so it's hard to say which
is "best" as it depends on one's point of view.
For example, I had a requirement to test more than just Python
programs. I wanted to test code written in any language. None of the
frameworks I found supported this so I wrote my own tester. It
interacts with programs via file streams - principally stdin, stdout
and stderr though others can be added as needed.

I was speaking to unit tests (tests of individual classes and
functions in isolation of the rest of the program) and a test driven
development approach. I find those to be much more useful, and good
for pinpointing bugs and guiding development. In contrast regression
tests tend to be slow, and are the programmatic equivalent of kicking
the tires and seeing if they fall off.
I agree with your points but would add

1. We should write smaller modules than we generally do. It promotes
clear thinking and encourages the production of reusable code. In
Python it is easy to add a __main__ section to interface to the
classes or functions defined in the code. Such code can then be tested
as mentioned. The functions or classes can still be imported into and
used in other code as needed.

2. The example given wasn't intended to be the only way forward but to
highlight that what makes a test package good depends on your
requirements (which I don't think you mentioned). In my case the
desire to test arbitrary languages was a killer blow to various Python-
only frameworks which I wasn't too impressed with anyway. (At least I
saw none that looked worth investing the time to learn.) Similarly an
option for you is to write your own tester. It may be a better fit
than someone else's package and not too hard to do. On the other hand
a pre-written package may be better - depending on what you are
looking for.

I've also seen regression tests lead to a "sweep the bugs under the
rug mentality" where developers will code to prevent errors from
crashing the regression test, e.g. by catching and swallowing all
exceptions without fixing the underlying problem. It's easy to fool
regression tests since what it does works at such a high level that
most aspects of program correctness can't be directly checked. This is
very frustrating to me because it actually leads to lower code
quality.

If you have dodgy developers then much is wrong, not just testing. If
the team works well, IMHO, production of test cases should be a
welcome part of the development process. When is it better to find
bugs: before or after shipping to a client? Test cases can be put
together in various ways. For example, if one has the code and chooses
to work this way white-box testing can lead to generation of test
cases. On the other hand if an organisation prefers it can produce
test cases from the spec - or they can do both. It's their choice but
in any case the developers and testers should work together.

One nice by-product is that test code does not bloat-out the original
source which remains unchanged.

That's the main reason most people don't write unit tests. It forces
them to properly decouple their code so that parts can be used
independently of one another. Adding such things to messy ball of mud
code after the fact is an enourmous pain in the butt. Thankfully,
since python is duck typed and doesn't require lots of boilerplate
writing interfaces and abstract factories (since the class object
itself acts as an abstract factory), writing properly decoupled code
in the first place doesn't look nearly as hard as in C++ or Java.
You could still import one Python module into another to run test
cases such as

-----
import test_support
import <program_to_be_tested>

<tests of program_to_be_tested using test_support>
-----

where the tests can interact directly with the components of the code
under test. The test support code can handle things such as collating
results and reporting as well as providing code to directly support
certain tests, handle exceptions etc.

I wouldn't be surprised if good testing code were in many cases to be
significantly longer than the code being tested. Keeping the tests in
a separate file keeps the code being tested shorter which can only
improve clarity. It also allows either the developer or someone else
to write the tests. Putting code and testing code in the same file
almost requires one person to write both parts.

A final thought: if you have dodgy developers who engineer their code
to avoid tests you're not going to have much success in getting them
to write good test code (though, hopefully, the mental process of
writing test cases should help them improve the code they write).

At the end of the day all I'm saying is that the best test framework
for you really depends on your requirements, rather than what others
think is "best" or not.

--
James
Nov 15 '08 #10
On 11 Nov., 23:59, Brendan Miller <catph...@catphive.netwrote:
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.
The UT frameworks follow the same principles and are all alike more or
less. Of course doctest makes a difference and implies another
approach to testing but whether you use unittest, nosetest or py.test
is mostly a matter of taste. Of course taste matters a lot for various
people and when they have to use CamelCased method names like setUp or
assertEqual in Python they feel alienated and reminded that Java is
out there.

Personally I use unittest.py for a pretty obvious reason: other people
can simply run the test scripts without prior installation of a
testframework.

Kay
Nov 15 '08 #11

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

Similar topics

467
by: mike420 | last post by:
THE GOOD: 1. pickle 2. simplicity and uniformity 3. big library (bigger would be even better) THE BAD:
38
by: kbass | last post by:
In different articles that I have read, persons have constantly eluded to the productivity gains of Python. One person stated that Python's...
23
by: assaf__ | last post by:
Hello, I am beginning to work on a fairly large project and I'm considering to use python for most of the coding, but I need to make sure first...
36
by: Andrea Griffini | last post by:
I did it. I proposed python as the main language for our next CAD/CAM software because I think that it has all the potential needed for it. I'm...
11
by: rhat | last post by:
Hi Everyone, I've recently been reading some articles about unit-testing in Python , but I am a bit confused: where do I go to get started with...
10
by: Andrew Dalke | last post by:
Is there an author index for the new version of the Python cookbook? As a contributor I got my comp version delivered today and my ego wanted some...
35
by: Alex Martelli | last post by:
Having fixed a memory leak (not the leak of a Python reference, some other stuff I wasn't properly freeing in certain cases) in a C-coded extension...
162
by: Sh4wn | last post by:
Hi, first, python is one of my fav languages, and i'll definitely keep developing with it. But, there's 1 one thing what I -really- miss: data...
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...
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...

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.