The Artima Developer Community
Sponsored Link

Python Buzz Forum
First look at test layers from zope.testing

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Baiju M

Posts: 225
Nickname: baijum81
Registered: Aug, 2004

Baiju M is a new user
First look at test layers from zope.testing Posted: Oct 31, 2006 9:56 PM
Reply to this message Reply

This post originated from an RSS feed registered with Python Buzz by Baiju M.
Original Post: First look at test layers from zope.testing
Feed Title: Programming life without Python(?)
Feed URL: http://baijum81.livejournal.com/data/rss
Feed Description: Programming life without Python(?)
Latest Python Buzz Posts
Latest Python Buzz Posts by Baiju M
Latest Posts From Programming life without Python(?)

Advertisement
Recently Zope team has released zope.testing version 3.0 .
For more info : http://cheeseshop.python.org/pypi/zope.testing
To install : # easy_install zope.testing

This is an independent testing framework which can be used outside Zope.
One of the interesting feature is test layers. I think next Zope 3 release (3.4)
will make use test layers heavily, so I started looking at this feature.

The test layer API is here:
http://svn.zope.org/zope.testing/trunk/src/zope/testing/testrunner-layers-api.txt?view=auto

I will show you a simple example.

First a 'hello.py':
def hello():
    return 'Hello'


Then 'tests.py':
import hello
import unittest

class FirstLayer(object):
    pass

class TestHello(unittest.TestCase):
    layer = FirstLayer
    def test_hello(self):
        assert hello.hello() == 'Hello'

def test_suite():
    return unittest.TestSuite((unittest.makeSuite(TestHello)))


The only thing to note here is the 'layer' attribute of 'TestHello' class.
We can add 'setUp' and 'tearDown' methods to 'FirstLayer' class.

Now create a script, 'runtest.py':
import sys
from zope.testing import testrunner
defaults = ['--test-path', '.', '--tests-pattern', 'tests$',]
testrunner.run(defaults)


When running the script, you will get something like:
Running tests.FirstLayer tests:
  Set up tests.FirstLayer in 0.000 seconds.
  Ran 1 tests with 0 failures and 0 errors in 0.000 seconds.
Tearing down left over layers:
  Tear down tests.FirstLayer in 0.000 seconds.

Read: First look at test layers from zope.testing

Topic: SQLAlchemy and Active Record Previous Topic   Next Topic Topic: Json, XML-RPC, Soap and TurboGears

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use