Join Club ShowMeDo to Learn Python!

This series is a part of Club ShowMeDo. Click to learn why you should join our club with a simple monthly subscription.

  • We teach Python and all the cool modules
  • Topics include beginner Python, GUIs, Web and Desktop Apps
  • Long, specially crafted video tutorials just for you
  • Club video tutorials extend our normal Free content
  • Save your time - we've done the research for you
  • Keep your skills up-to-date
  • Learn at your own pace, everything you need is shown to you
  • Over 12 hours of archived material are waiting for you in the club

Name: [002] Ian Ozsvald
Member: 129 months
Authored: 181 videos
Description: I am the co-founder of ShowMeDo (see, author of `The Screencasting Handbook <>`_ and the founder of the professional screencast production company `ProCasts <>`_: .. image:: ...

Test for a 404 Not Found [ID:600] (3/5)

in series: Robust and Reliable Web Sites with twill and nosetests

(Showmedo is undergoing major changes. To report any problems viewing the videos please email us and include browser and OS specifics. Cheers - Kyran.)

Next we check that an incorrect URL generates a 404 Not Found error. Use this to confirm your error-handling as Not Found errors are very common on live websites.

from twill.commands import *

# usage examples:
# nosetests - try all tests that nosetests can find
# nosetests - call all tests in the file
# nosetests

# twill API reference

def test_homepage_OK():
    "test we can get to the homepage"
    # 200
    http_code = b.result.get_http_code()    
    print "http_code", http_code
    assert http_code == 200
def test_404():
    "test that a bad url generates a 404 error"
    # 404 OK
    http_code = b.result.get_http_code()    
    print http_code
    assert http_code == 404

Got any questions?

Get answers in the ShowMeDo Learners Google Group.

Video statistics:

  • Video's rank shown in the most popular listing
  • Video plays: 0 (since July 30th)
  • Plays in last week: 0
  • Published: 101 months ago

Thank-yous, questions and comments

If this video tutorial was helpful please take some time to say thank-you to the authors for their hard work. Feel free to ask questions. Let the author know why their video tutorial was useful - what are you learning about? Did the video tutorial save you time? Would you like to see more?

You may also want to see our ShowMeDo Google Group to speak to our active users and authors.

Your email address will not be published.

Show some quick comments >>

All comments excluding tick-boxed quick-comments

This is great. I had never heard about Twill before this.

One thing that would help focus the material would be to add to the text notes something such as:

Twill automates interaction with webpages, statefully following links, parsing pages and filling and retrieving forms.

Nose is a testing framework[1]. In this episode we write nosetests that use twill to interact with webpages and demonstrate that;

A. nosetests can extract and run all possible tests in the current working directory

B. nosetests can be restricted to specific files and further to specific functions within those files


Hi André and Lucas! See the last video in this series for interacting with a website via forms - we use form interaction to test logins and video uploads (as discussed in that video).

André - I don't think you can test JavaScript in the way you say - twill can be used to visit a page and test the returned html but it doesn't interpret javascript.

To interpret javascript I guess you need Selenium - it is a full 'browerser tester' environment from what I've heard...I've always meant to look into it as it is used for AJAX testing, but I've never (yet) needed it. Maybe that's another topic for the future.



Ian, once again you prove to be a great teacher. I'm definitely learning something new here (as I've never really bothered to test my code (yes, I admit: I'm an idiot ;-))).

I'll probably be working on a Django project soon, so this will definitely come in handy!!!

I'd also be interested in more complex examples, stuff like creating a new user on showmedo and making sure that user can log in okay etc.

(If that's possible with twill/nosetests of course ;-))

How about some more complicated tests arising from some complicated page interaction. For example, suppose I have a page with a text area and a button and some javascript code. You type your name in the textarea, click on the button and the output "Hello name" appears on the page. Can twill do this?

If so, it would be wonderful. :-)

Video published, thanks for contributing to ShowMeDo

Showmedo is a peer-produced video-tutorials and screencasts site for free and open-source software (FOSS)- with the exception of some club videos, the large majority are free to watch and download.

how to help » about » faq »

Educating the Open-source Community With Showmedo

Although as important as the software it supports, education and documentation are relatively neglected in the Open-source world. Coders love to code, and explaining how best to use or improve the software tends to be deferred or even sidelined.

At Showmedo we believe the community can play a vital role here and also say thanks for the tools and software that make our lives easier. If you have a piece of software you love or a programming langugage you are enthusiastic about, why not make a screencast showing others how to use it? All the stuff you wish you'd been told, the tips, tricks, insights that would have saved you time and frustration.

Screencasting is easier than you think, and we're happy to help you. You can emailus for advice or just use some of the how-to screencasts on the site. This screencasting learning-pathis a good place to start.

Kudos and Thanks for Ian

3 Minute Oveview (What Does Python Look Like?)

simple and informative. you draw me in
70 months ago


Showmedo's development is fairly rapid and bugs will inevitably creep in. If you have any problems please drop us a line using the contact address below. Likewise, any suggestions for improvements to the site are gratefully received.