Decorators and buffer flushing

Discussion in 'Python' started by Ethan Metsger, Feb 28, 2008.

  1. Hi, all.

    I apologize for what is perhaps a newb question. I'm in the process of
    transitioning our testing framework from Perl to Python. While that alone
    probably sets off some red flags, I'm afraid it's what I'm stuck with.

    I'm modeling a test with five operations: build, execute, validate,
    publish, and clean. The main loop might look something like this:

    with Test(...) as t:
    t.build()
    t.execute()
    t.validate()
    t.publish()

    At each run, I want to output a '.' to denote completion of that test
    step. I've been able to do this, sort of, using the following decorator
    (edited for brevity):

    def report(f):

    def new(self):
    stat = f(self);

    if stat is True:
    sys.stdout.write ('.')

    else:
    ...

    sys.stdout.flush()

    return new

    (Each one of the test functions returns True or False depending on its
    completion status.)

    The problem is that rather than outputting a period after each step is
    completed, it outputs all four of them at once. Instead of seeing
    progress as it happens, I get it when it's finished, even though I'm
    flushing the output buffer.

    Any thoughts?


    Best,

    Ethan ()
    http://uppertank.net/ethanm/
    Ethan Metsger, Feb 28, 2008
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Eric

    Flushing the Buffer in .Net

    Eric, Apr 25, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    601
  2. arnuld
    Replies:
    5
    Views:
    787
    =?ISO-8859-1?Q?Erik_Wikstr=F6m?=
    Mar 18, 2007
  3. Andyza

    Flushing servers buffer

    Andyza, Jul 6, 2005, in forum: ASP General
    Replies:
    3
    Views:
    122
    Andyza
    Jul 7, 2005
  4. tj
    Replies:
    2
    Views:
    143
    Walter Roberson
    May 4, 2004
  5. Nigel

    Problems flushing my buffer! (perl)

    Nigel, Oct 3, 2008, in forum: Perl Misc
    Replies:
    14
    Views:
    221
    Jim Gibson
    Oct 7, 2008
Loading...

Share This Page