1. holger krekel
  2. py-trunk
Issue #4 invalid

pytest_twisted-plugin calls test-functions/method twice.

mzeidler
created an issue

Every test-function/method are called twice using the pytest-twisted plugin.

To reproduce that issue:

  1. Put in ' pytest_plugins = "twisted", ' into the conftest.py
  2. Test attached file 'py.test -s -T test_some.py'

In the twisted-plugin: {{{

!python

def pytest_pyfunc_call(self, pyfuncitem, args, kwargs): print "pyfuncitem: ", pyfuncitem if self.twisted: def wrapper(func): """ wrapper just to pass back (injecting) the test-function into doit() by using a greenlet switch. """ if hasattr(func, 'obj'): # XXX: what about kwargs? #res = gr_twisted.switch(lambda: func.obj(args)) res = gr_twisted.switch(lambda: func.obj(*args)) if res: res.raiseException() pyfuncitem = wrapper(pyfuncitem) }}}

the wrapper passes a lambda-function including the actual test-function by using a greenlet-switch to doit() in which the function acutally gets called by 'defer.maybeDeferred(res).addCallback(done).addErrback(err)'. In 'pytest_pyfunc_call()' s.th. would be needed to switch of the usual py.test test function call.

Comments (5)

  1. holger krekel repo owner

    more or less fixes #4 along with changeset e07b15140498

    note that i don't understand why the twisted plugin went through the "wrapper" function. seems to work just fine for me without it. also added the "True" return value which indicates we handled the call. however, the plugin hook will need some refinments. see XXXs.

    31d6c07f020f

  2. mzeidler reporter
    • changed status to open

    Nice that the wrapper is anymore needed. Let's say this was legacy code in times where monkey patching was needed for py..test.item.Function.execute.

    But testing test_some.py with py.test -s -T --twisted-logging test_some.py still produces the following indicating that the collected items are tested twice. See e.g. the occurrence of '11111111111111111111':

    python: platform linux2 -- Python 2.5.2
    using py lib: /usr/lib64/python2.5/site-packages/py <rev unknown>
    test object 1: /home/mike/devel/py.test/pytest_twisted/_delete_me
    2009-04-24 12:50:50+0200 [-] TestTwistedSetupMethod.setup_method() called
    in setup_method
    pyfuncitem:  <Function 'test_deferred'>
    11111111111111111111
    2009-04-24 12:50:50+0200 [-] TestTwistedSetupMethod.test_deferred() called
    2009-04-24 12:50:50+0200 [-] TestTwistedSetupMethod.test_deferred() returning deferred: <Deferred at 0xbeac68>
    2009-04-24 12:50:53+0200 [-] TestTwistedSetupMethod.test_deferred() CALLBACK DONE
    11111111111111111111
    2009-04-24 12:50:53+0200 [-] TestTwistedSetupMethod.test_deferred() called
    2009-04-24 12:50:53+0200 [-] TestTwistedSetupMethod.test_deferred() returning deferred: <Deferred at 0xbeacf8>
    
    test_some.py .pyfuncitem:  <Function 'test_deferred'>
    22222222222222222222
    2009-04-24 12:50:53+0200 [-] TestTwistedSetupMethod.test_deferred() called
    2009-04-24 12:50:53+0200 [-] TestTwistedSetupMethod.test_deferred() returning deferred: <Deferred at 0xcd6878>
    2009-04-24 12:50:55+0200 [-] TestTwistedSetupMethod.test_deferred() CALLBACK DONE
    2009-04-24 12:50:55+0200 [-] TestTwistedSetupMethod.test_deferred() CALLBACK DONE
    22222222222222222222
    2009-04-24 12:50:55+0200 [-] TestTwistedSetupMethod.test_deferred() called
    2009-04-24 12:50:55+0200 [-] TestTwistedSetupMethod.test_deferred() returning deferred: <Deferred at 0xbeacf8>
    .pyfuncitem:  <Function 'test_deferred'>
    333333333333333333333
    2009-04-24 12:50:55+0200 [-] TestTwistedSetupMethod.test_deferred() called
    2009-04-24 12:50:55+0200 [-] TestTwistedSetupMethod.test_deferred() returning deferred: <Deferred at 0xcd6440>
    2009-04-24 12:50:58+0200 [-] TestTwistedSetupMethod.test_deferred() CALLBACK DONE
    2009-04-24 12:50:58+0200 [-] TestTwistedSetupMethod.test_deferred() CALLBACK DONE
    333333333333333333333
    2009-04-24 12:50:58+0200 [-] TestTwistedSetupMethod.test_deferred() called
    2009-04-24 12:50:58+0200 [-] TestTwistedSetupMethod.test_deferred() returning deferred: <Deferred at 0xbeacf8>
    
  3. Log in to comment