Slashdot Mirror


Testing Frameworks in Python

An anonymous reader writes "This article looks at Python's two standard modules for unit testing: unittest and doctest. These modules expand on the capability of the built-in assert statement, which is used for validation of pre-conditions and post-conditions within functions. The author discusses the best ways to incorporate testing into Python development, weighing the advantages of different styles for different types of projects."

12 of 120 comments (clear)

  1. Traditional testers might be interested... by tcopeland · · Score: 5, Informative

    ...in Bret Pettichord's Scripting for Testers one day class.

    It talks about eliminating some of the tediousness from testing web applications, mainly by using automated solutions like WTR.

    He's also got a list of testing resources that's got some good stuff in there...

  2. bull by kpharmer · · Score: 5, Informative

    A few thoughts:

    1. I've never had a problem with memory management in python. Can't say it doesn't exist, just never impacted my production applications.

    2. Implementing great built-in test frameworks doesn't need to wait for memory management improvements. I'm seeing almost immediate pay-offs from this kind of built-in testing.

    3. I'm implementing python as an alternative to java in large applications - with complete success. Easy to learn, easy to maintain, fast enough to handle millions of rows of data a day - what's not to like?

  3. Re:Python's dirty little secret by gaj · · Score: 3, Informative
    Um ... you'd have much more credibility if you at least got his name right.

    It's Guido van Rossum.

    As for your claims about the GC, I was under the impression that current versions of Python have a hybrid GC that cleans up circ-refs. I certainly could be mistaken, though, as I've been exiled to Java-land for the last several years.

  4. Testing.. by MosesJones · · Score: 4, Informative


    I hate to break it to the hack and slashdot crowd, but Testing is actually a whole career in itself, and the application of different testing processes and methods to different projects is a critical part of ensuring projects succeed.

    This article covers NOTHING about the different types of testing on a project, or indeed how test cases should even be constructed. Its basically about some UnitTesting elements that could be done by testing.

    I know its unpopular here on Slashdot to claim that there are more developers working on big projects than people hacking in Python. Buts its articles like these that underline the difference between professional software development and hacking.

    This is about hacking.

    --
    An Eye for an Eye will make the whole world blind - Gandhi
  5. Re:Python's dirty little secret by Anonymous Coward · · Score: 3, Informative

    "As for your claims about the GC, I was under the impression that current versions of Python have a hybrid GC that cleans up circ-refs."


    According to this you are correct.

    BUT.. please note it also says "You can run gc.collect() to force a collection, but there are pathological cases where objects will never be collected."

    It also mentions the use of weakrefs. :)
  6. Re:Python's dirty little secret by smallpaul · · Score: 5, Informative

    It is clear you do not know anything about Python. You are not a long-time Python developer but rather a troll. The first hint is that you misspell Guido Van Rossum's name.

    The second hint is that you cite a page from 1999. A Python developer would know that that was before Python had cyclic garbage collection. Here is an article from 2001 that describes how the issue was fixed.

    The third hint is that you point to a page that describes how to avoid creating a memory leak by appending an infinite number of items to a list. Guess what: appending an infinite number of items to a list causes a memory leak in Java, C++, C, assembly, Scheme, sh, Perl and every other programming language in the world. If you ask the computer to store a continually growing list of items, it will do so...in any language.

    If you think that Python can leak memory in circumstances where other languages would not, post an example program and we'll all test it out.

  7. Re:Python's dirty little secret by Lulu+of+the+Lotus-Ea · · Score: 4, Informative

    FWIW, I'm the author of the referenced testing article. Though that's not really germane to the following comment.

    b.foster's misguided comment gives a link to a 1999 article about problems in Python with cleaning up circular references. Well, yeah: in 1999, Python 1.5.2 could leak on circular references. It was actually less of a problem in practice than advocates of mark-and-sweep collectors tended to complain about; but it really was a limitation. That was a long time ago.

    Nowadays, Python still uses references counting as its primary collection mechanism. It's a nice system: fast, deterministic, etc. (despite what you might think, refcount *really is* faster than Bohm generational; and is well-tested as such by very smart Python developers). However, the last half-decade of Python versions also perform occassional checks for orphaned objects, and cleans them up too. The "problem" pointed to is of historical interest, at most.

  8. Re:Python's dirty little secret by smallpaul · · Score: 3, Informative

    Argh...the garbage collector does handle circular references automatically and has done so for at least two years. Weak references are something totally different and are used e.g. for caches.

  9. Re:Different types of project ? by Simon+Lyngshede · · Score: 2, Informative

    It is a very short article about using the unit testing framework for Python, not the definitive guide to testing. Do you even understand how amazingly large a subject software testing is?

    I think that unit testing is an important tool, it allow you to easily continue to do integration test and regression testing, if you know what you're doing.

    I will however agree with you on the "get a book on testing" part. I think it's important that anyone who develop software, understand what is involved in testing.

  10. Re:Why Python? by dubious9 · · Score: 3, Informative

    First off, I had mod points and I feel bad about not modding you up, and you don't deserve a 0:offtopic score.But I though a responce would be better.

    Can someone help me understand why I would want to use Python as opposed to Java?

    Python is not just about brevity, but I think you underestimate writing less lines of code. Take the fact that if you are writing twice as much code, you're probably writing twice as many bugs. Also a consise 50K LOC program is much easier to get around in than a 200K program.

    But anyway, Python is an interpreted, interactive, object-oriented programming language., where as Java is only the last of those three. Python also has dynamic documentation, meaning that the documentation string can be inspected at run-time, without the need to maintain a separate doc tree, ie Javadoc.

    Classes are dynamic ie. you can change their behavior at runtime. All python objects can be marshalled or serialized, while in Java you have to define the interface, and account for anything that you use that can't be serialized.

    There are also thing which I am indifferent about like tabbed blocks, and some things which I don't like, like not having enough compile time type checking. IMHO you should always define the type of a function parameter, it makes learning the API faster.

    In general, Python is great for script-strength stuff, ie. in situations where you would use perl. I can see it getting unwieldly as it got bigger but it generally scales much better then perl. Java tends to be too complex and too restrictive. In short there are many situations where you would choose one over the other.

    --
    Why, o why must the sky fall when I've learned to fly?
  11. Integrating the two approaches by teknico · · Score: 2, Informative

    Here is a presentation, with PDF article, about integrating the two approaches, straight from recent PyCon:

    Literate Testing: Automated Testing with doctest

  12. Re:Why Python? by Daath · · Score: 2, Informative

    Try reading ESR's Why Python?, also check out the Quotes on Python from python.org :)
    It's a beautiful language, I'm sorry I can't code in it more...

    --
    Any technology distinguishable from magic, is insufficiently advanced.