[TIP] PyBehave ?!?

Michał Kwiatkowski constant.beta at gmail.com
Mon Mar 12 05:49:20 PDT 2007


On 3/12/07, Raphael Marvie <raphael.marvie at lifl.fr> wrote:
> Is any one working on a python implementation of jBehave or something
> similar to jBehave in a python way? I am thinking of having a look at
> it, but want to check first if someone is already on the track.

I didn't heard of any Python framework for BDD, but it doesn't mean
you can't achieve the same effect with currently existing tools. There
is unittest and doctest in standard library, there is
python-mock[1]/pyMock[2]/minimock[3] for mocking and stubbing, there
is nose[4] for running test, figleaf[5] for code coverage, spec
plugin[6] for specifications. What is missing is this small shift in
terminology, which IMHO isn't really needed if people already know
what TDD is about. But if you insist you could try to come up with
some nice syntax for setting contexts and specs. I would use "with"
keyword to achieve syntax similar to:

with context("Empty queue") as c:
    with setup():
        c.queue = Queue()
    with spec("should be empty"):
        assert Queue.isempty() is True

Another issue of changing asserts into expectations could be more
tricky. Using jBehave-like syntax you would like to change assert
above into:

    ensure_that(Queue.isempty(), eq(True))

IMHO this is not easier to read and may sometimes be even less clear
(as people are used to asserts already). RSpec[7] has much nicer
syntax, but without open object class in Python this cannot be
achieved in any standard way:

    Queue.should_be_empty()

What I suggest is to build on top of existing tools to prevent
reinventing the wheel. If you like jBehave syntax, create a
unittest.TestCase derivative so it integrates nicely with whatever
people are using now. If you feel your mocking library is missing
important features, contribute patches. You may actually end up
writing a nice tutorial which describes specific setup for doing BDD
without actually creating any new framework. Oh, and remember I only
scratched a surface of existing Python testing tools. More
comprehensive list is on Cheesecake wiki[8].

[1] http://python-mock.sourceforge.net/
[2] http://theblobshop.com/pymock/
[3] http://blog.ianbicking.org/minimock.html
[4] http://somethingaboutorange.com/mrl/projects/nose/
[5] http://darcs.idyll.org/~t/projects/figleaf/README.html
[6] included in pinocchio package:
http://darcs.idyll.org/~t/projects/pinocchio/doc/
[7] http://rspec.rubyforge.org/
[8] http://pycheesecake.org/wiki/PythonTestingToolsTaxonomy

Cheers,
mk



More information about the testing-in-python mailing list