[ANN] Oktest 0.9.0 released - a new-style testing library

M

Makoto Kuwata

Hi,

I released Oktest 0.9.0.
http://pypi.python.org/pypi/Oktest/
http://packages.python.org/Oktest/

Oktest is a new-style testing library for Python.
::

from oktest import ok, NG
ok (x) > 0 # same as assert_(x > 0)
ok (s) == 'foo' # same as assertEqual(s, 'foo')
ok (s) != 'foo' # same as assertNotEqual(s, 'foo')
ok (f).raises(ValueError) # same as assertRaises(ValueError, f)
ok (u'foo').is_a(unicode) # same as assert_(isinstance(u'foo', unicode))
NG (u'foo').is_a(int) # same as assert_(not isinstance(u'foo', int))
ok ('A.txt').is_file() # same as assert_(os.path.isfile('A.txt'))
NG ('A.txt').is_dir() # same as assert_(not os.path.isdir('A.txt'))

See http://packages.python.org/Oktest/ for details.

NOTICE!! Oktest is a young project and specification may change in the future.


Main Enhancements
-----------------

* New '@test' decorator provided. It is simple but very powerful.
Using @test decorator, you can write test description in free text
instead of test method.
ex::

class FooTest(unittest.TestCase):

def test_1_plus_1_should_be_2(self): # not cool...
self.assertEqual(2, 1+1)

@test("1 + 1 should be 2") # cool! easy to read & write!
def _(self):
self.assertEqual(2, 1+1)

* Fixture injection support by '@test' decorator.
Arguments of test method are regarded as fixture names and
they are injected by @test decorator automatically.
Instance methods or global functions which name is 'provide_xxxx' are
regarded as fixture provider (or builder) for fixture 'xxxx'.
ex::

class SosTest(unittest.TestCase):

##
## fixture providers.
##
def provide_member1(self):
return {"name": "Haruhi"}

def provide_member2(self):
return {"name": "Kyon"}

##
## fixture releaser (optional)
##
def release_member1(self, value):
assert value == {"name": "Haruhi"}

##
## testcase which requires 'member1' and 'member2' fixtures.
##
@test("validate member's names")
def _(self, member1, member2):
assert member1["name"] == "Haruhi"
assert member2["name"] == "Kyon"

Dependencies between fixtures are resolved automatically.
ex::

class BarTest(unittest.TestCase):

##
## for example:
## - Fixture 'a' depends on 'b' and 'c'.
## - Fixture 'c' depends on 'd'.
##
def provide_a(b, c): return b + c + ["A"]
def provide_b(): return ["B"]
def provide_c(d): return d + ["C"]
def provide_d(): reutrn ["D"]

##
## Dependencies between fixtures are solved automatically.
##
@test("dependency test")
def _(self, a):
assert a == ["B", "D", "C", "A"]

If loop exists in dependency then @test reports error.

If you want to integrate with other fixture library, see the following
example::

class MyFixtureManager(object):
def __init__(self):
self.values = { "x": 100, "y": 200 }
def provide(self, name):
return self.values[name]
def release(self, name, value):
pass

oktest.fixure_manager = MyFixtureResolver()



Other Enhancements and Changes
------------------------------

* Supports command-line interface to execute test scripts.
* Reporting style is changed.
* New assertion method ``ok(x).attr(name, value)`` to check attribute.
* New assertion method ``ok(x).length(n)``.
* New feature``ok().should`` helps you to check boolean method.
* 'ok(str1) == str2' displays diff if text1 != text2, even when using
with unittest module.
* Assertion ``raises()`` supports regular expression to check error message.
* Helper functions in oktest.dummy module are now available as decorator.
* 'AssertionObject.expected' is renamed to 'AssertionObject.boolean'.
* ``oktest.run()`` is changed to return number of failures and errors of tests.
* ``before_each()`` and ``after_each()`` are now non-supported.
* (Experimental) New function ``NOT()`` provided which is same as ``NG()``.
* (Experimental) ``skip()`` and ``@skip.when()`` are provided to skip tests::

See CHANGES.txt for details.
http://packages.python.org/Oktest/CHANGES.txt


Have a nice testing life!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,905
Latest member
Kristy_Poole

Latest Threads

Top