Skip to content

Asynchronously supercalling setUp or tearDown fails #547

@jelmer

Description

@jelmer

Migrated from Launchpad: https://bugs.launchpad.net/bugs/1819078

Original Reporter: Jean-Paul Calderone
Date Created: 2019-03-07 23:48:12.684798+00:00
Status on Launchpad: New
Importance: Undecided


I expected this would be a valid test case:

from testtools import TestCase
from testtools.twistedsupport import AsynchronousDeferredRunTest
from twisted.internet.defer import Deferred

class X(TestCase):
    run_tests_with = AsynchronousDeferredRunTest

    def setUp(self):
        d = Deferred()
        d.addCallback(lambda ignored: super(X, self).setUp())
        self.reactor.callLater(0.0, d.callback, None)
        return d

    def test_foo(self):
        pass

However, it fails:

===============================================================================
[ERROR]
Traceback (most recent call last):
Failure: testtools.testresult.real._StringException: Empty attachments:
  twisted-log

traceback-1: {{{
Traceback (most recent call last):
  File "/home/exarkun/Environments/tahoe-lafs/local/lib/python2.7/site-packages/testtools/twistedsupport/_runtest.py", line 386, in _log_user_exception
    raise e
testtools.twistedsupport._runtest.UncleanReactorError: The reactor still thinks it needs to do things. Close all connections, kill all processes and make sure all delayed calls have either f
ired or been cancelled:
  <DelayedCall 0x7fc94d489ab8 [-0.00155591964722s] called=0 cancelled=1>
}}}

Traceback (most recent call last):
  File "/home/exarkun/Environments/tahoe-lafs/local/lib/python2.7/site-packages/twisted/internet/defer.py", line 151, in maybeDeferred
    result = f(*args, **kw)
  File "/home/exarkun/Environments/tahoe-lafs/local/lib/python2.7/site-packages/testtools/testcase.py", line 688, in _run_setup
    self.__class__.__name__))
ValueError: In File: /tmp/asyncfixture.py
TestCase.setUp was not called. Have you upcalled all the way up the hierarchy from your setUp? e.g. Call super(X, self).setUp() from your setUp().


asyncfixture.X.test_foo
-------------------------------------------------------------------------------

The check for upcalling happens synchronously and independent of the Twisted support being applied.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions