O'Reilly logo

Python Testing Beginner's Guide by Daniel Arbuckle

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Time for action - running Twill script files

The first way is to store the Twill script in a separate file, and then use the twill.parse.execute_file function to run it.

  1. Place the following code into a file called fail.twill:
    go http://slashdot.org/
    find this_does_not_exist
    
  2. Naturally, this script will fail, but go ahead and run it with twill‑sh to see for yourself.
    $ twill-sh fail.twill
    
    
  3. Now to run the script from Python. Pull up an interactive Python shell and do the following:
    >>> from twill.parse import execute_file
    >>> execute_file('fail.twill')
    
    
    Time for action - running Twill script files
  4. Simple as that, we ran the script from inside Python code. That would work equally well in doctest, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required