[ANN] Oktest.py 0.10.0 released - a new-style testing library

Makoto Kuwata kwa at kuwata-lab.com
Sun Nov 6 23:12:58 EST 2011


Hi,

I released Oktest.py 0.10.0.
http://packages.python.org/Oktest/
http://www.kuwata-lab.com/oktest/

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

    from oktest import ok, NG
    ok (x) > 0                 # same as assertTrue(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 assertTrue(isinstance(u'foo', unicode))
    NG (u'foo').is_a(int)      # same as assertTrue(not isinstance(u'foo', int))
    ok ('A.txt').is_file()     # same as assertTrue(os.path.isfile('A.txt'))
    NG ('A.txt').is_dir()      # same as assertTrue(not os.path.isdir('A.txt'))

See
  http://www.kuwata-lab.com/oktest/oktest-py_users-guide.html
for details.


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

* [change] 'oktest.spec()' is obsoleted completely.
  It will print warning message if you use it.

* [change] 'oktest.helper' module is renamed to 'oktest.util'.
  ('oktest.helper' is still available for backward compabibility.)

* [enhance] Add 'oktest.main()' which is a replacement of 'oktest.run()'.
  Using 'oktest.main()' instead of 'oktest.run()', command options are
available.
  ex::

    ## for example:
    $ python test/foobar_test.py -sp -f test='*keyword*'
    ## is almost same as:
    $ python -m oktest test/foobar_test.py -sp -f test='*keyword*'

* [enhance] Add 'oktest.fail(message)' which is same as
'unittest.fail(message)'.
  ex::

    from oktest import fail
    fail("not impelmented yet")    # will raise AssertionError

* [enhance] (Experimental) Add '@todo' decorator which is equivarent to
  '@unittest.expectedFailure'.
  ex::

    from oktest import ok, test, todo

    def add(x, y):
        return 0      # not implemented yet!

    class AddTest(unittest.TestCase):
        @test("returns sum of arguments.")
	@todo         # equivarent to @unittest.expectedFailure
        def _(self):
	    ok (10, 20) == 30   ## will be failed expectedly
	                        ## (because not implemented yet)

  Expected failure of assertion is reported as '[TODO]', not '[Failed]'.

* [enhance] (Experimental) Test context supported.
  It helps you to describe specification in structured style.
  ex::

    from oktest import ok, test
    from oktest.context import subject, situation

    class SampleTestCase(unittest.TestCase):
      SUBJECT = "class 'Sample'"

      with subject("method1()"):

        with situation("when condition:"):

          @test("spec1")
            def _(self):
            ...

          @test("spec2")
          def _(self):
            ...

        with situation("else:"):

          @test("spec3")
          def _(self):
            ...

  Output exmple::

    $ python test/example_test.py
    * class 'Sample'
      + method1()
        + when condition:
	  - [ok] spec1
	  - [ok] spec2
        + else:
	  - [ok] spec3
    ## total:3, passed:3, failed:0, error:0, skipped:0   (elapsed 0.000)


--
regards,
makoto kuwata



More information about the Python-list mailing list