testtools-dev team mailing list archive
-
testtools-dev team
-
Mailing list archive
-
Message #00308
[Merge] lp:~jml/testtools/skip-dont-elide into lp:testtools
Jonathan Lange has proposed merging lp:~jml/testtools/skip-dont-elide into lp:testtools.
Requested reviews:
testtools developers (testtools-dev)
Related bugs:
#668511 fixture tests should SKIP not be elided
https://bugs.launchpad.net/bugs/668511
#668516 Twisted tests should skip, not be elided
https://bugs.launchpad.net/bugs/668516
This branch makes all of the tests that rely on fixtures or Twisted skip instead of not being included in the test run in the first place.
I don't know if there's a nicer way to do this.
--
https://code.launchpad.net/~jml/testtools/skip-dont-elide/+merge/42003
Your team testtools developers is requested to review the proposed merge of lp:~jml/testtools/skip-dont-elide into lp:testtools.
=== modified file 'testtools/tests/__init__.py'
--- testtools/tests/__init__.py 2010-10-31 18:14:24 +0000
+++ testtools/tests/__init__.py 2010-11-27 11:31:58 +0000
@@ -10,10 +10,13 @@
test_compat,
test_content,
test_content_type,
+ test_deferredruntest,
+ test_fixturesupport,
test_helpers,
test_matchers,
test_monkey,
test_runtest,
+ test_spinner,
test_testtools,
test_testresult,
test_testsuite,
@@ -23,34 +26,17 @@
test_compat,
test_content,
test_content_type,
+ test_deferredruntest,
+ test_fixturesupport,
test_helpers,
test_matchers,
test_monkey,
test_runtest,
+ test_spinner,
test_testresult,
test_testsuite,
test_testtools,
]
- try:
- # Tests that rely on Twisted.
- from testtools.tests import (
- test_deferredruntest,
- test_spinner,
- )
- except ImportError:
- pass
- else:
- modules.extend([test_deferredruntest, test_spinner])
- try:
- # Tests that rely on 'fixtures'.
- from testtools.tests import (
- test_fixturesupport,
- )
- except ImportError:
- pass
- else:
- modules.extend([test_fixturesupport])
-
for module in modules:
suites.append(getattr(module, 'test_suite')())
return unittest.TestSuite(suites)
=== modified file 'testtools/tests/test_deferredruntest.py'
--- testtools/tests/test_deferredruntest.py 2010-11-12 11:30:23 +0000
+++ testtools/tests/test_deferredruntest.py 2010-11-27 11:31:58 +0000
@@ -12,12 +12,7 @@
from testtools.content import (
text_content,
)
-from testtools.deferredruntest import (
- assert_fails_with,
- AsynchronousDeferredRunTest,
- flush_logged_errors,
- SynchronousDeferredRunTest,
- )
+from testtools.helpers import try_import
from testtools.tests.helpers import ExtendedTestResult
from testtools.matchers import (
Equals,
@@ -26,9 +21,19 @@
Raises,
)
from testtools.runtest import RunTest
-
-from twisted.internet import defer
-from twisted.python import failure, log
+from testtools.tests.test_spinner import NeedsTwistedTestCase
+
+assert_fails_with = try_import('testtools.deferredruntest.assert_fails_with')
+AsynchronousDeferredRunTest = try_import(
+ 'testtools.deferredruntest.AsynchronousDeferredRunTest')
+flush_logged_errors = try_import(
+ 'testtools.deferredruntest.flush_logged_errors')
+SynchronousDeferredRunTest = try_import(
+ 'testtools.deferredruntest.SynchronousDeferredRunTest')
+
+defer = try_import('twisted.internet.defer')
+failure = try_import('twisted.python.failure')
+log = try_import('twisted.python.log')
class X(object):
@@ -77,7 +82,7 @@
self.calls.append('test')
self.addCleanup(lambda: 1/0)
- class TestIntegration(TestCase):
+ class TestIntegration(NeedsTwistedTestCase):
def assertResultsMatch(self, test, result):
events = list(result._events)
@@ -104,9 +109,9 @@
from unittest import TestSuite
from testtools import clone_test_with_new_id
runners = [
- RunTest,
- SynchronousDeferredRunTest,
- AsynchronousDeferredRunTest,
+ ('RunTest', RunTest),
+ ('SynchronousDeferredRunTest', SynchronousDeferredRunTest),
+ ('AsynchronousDeferredRunTest', AsynchronousDeferredRunTest),
]
tests = [
@@ -118,12 +123,12 @@
]
base_test = X.TestIntegration('test_runner')
integration_tests = []
- for runner in runners:
+ for runner_name, runner in runners:
for test in tests:
new_test = clone_test_with_new_id(
base_test, '%s(%s, %s)' % (
base_test.id(),
- runner.__name__,
+ runner_name,
test.__name__))
new_test.test_factory = test
new_test.runner = runner
@@ -131,7 +136,7 @@
return TestSuite(integration_tests)
-class TestSynchronousDeferredRunTest(TestCase):
+class TestSynchronousDeferredRunTest(NeedsTwistedTestCase):
def make_result(self):
return ExtendedTestResult()
@@ -185,7 +190,7 @@
('stopTest', test)]))
-class TestAsynchronousDeferredRunTest(TestCase):
+class TestAsynchronousDeferredRunTest(NeedsTwistedTestCase):
def make_reactor(self):
from twisted.internet import reactor
@@ -602,10 +607,11 @@
self.assertThat(error, KeysEqual('traceback', 'twisted-log'))
-class TestAssertFailsWith(TestCase):
+class TestAssertFailsWith(NeedsTwistedTestCase):
"""Tests for `assert_fails_with`."""
- run_tests_with = SynchronousDeferredRunTest
+ if SynchronousDeferredRunTest is not None:
+ run_tests_with = SynchronousDeferredRunTest
def test_assert_fails_with_success(self):
# assert_fails_with fails the test if it's given a Deferred that
=== modified file 'testtools/tests/test_fixturesupport.py'
--- testtools/tests/test_fixturesupport.py 2010-10-28 20:18:39 +0000
+++ testtools/tests/test_fixturesupport.py 2010-11-27 11:31:58 +0000
@@ -1,20 +1,26 @@
import unittest
-import fixtures
-from fixtures.tests.helpers import LoggingFixture
-
from testtools import (
TestCase,
content,
content_type,
)
+from testtools.helpers import try_import
from testtools.tests.helpers import (
ExtendedTestResult,
)
+fixtures = try_import('fixtures')
+LoggingFixture = try_import('fixtures.tests.helpers.LoggingFixture')
+
class TestFixtureSupport(TestCase):
+ def setUp(self):
+ super(TestFixtureSupport, self).setUp()
+ if fixtures is None or LoggingFixture is None:
+ self.skipTest("Need fixtures")
+
def test_useFixture(self):
fixture = LoggingFixture()
class SimpleTest(TestCase):
=== modified file 'testtools/tests/test_spinner.py'
--- testtools/tests/test_spinner.py 2010-11-11 09:46:18 +0000
+++ testtools/tests/test_spinner.py 2010-11-27 11:31:58 +0000
@@ -9,90 +9,91 @@
skipIf,
TestCase,
)
+from testtools.helpers import try_import
from testtools.matchers import (
Equals,
Is,
MatchesException,
Raises,
)
-from testtools._spinner import (
- DeferredNotFired,
- extract_result,
- NoResultError,
- not_reentrant,
- ReentryError,
- Spinner,
- StaleJunkError,
- TimeoutError,
- trap_unhandled_errors,
- )
-
-from twisted.internet import defer
-from twisted.python.failure import Failure
-
-
-class TestNotReentrant(TestCase):
+
+_spinner = try_import('testtools._spinner')
+
+defer = try_import('twisted.internet.defer')
+Failure = try_import('twisted.python.failure.Failure')
+
+
+class NeedsTwistedTestCase(TestCase):
+
+ def setUp(self):
+ super(NeedsTwistedTestCase, self).setUp()
+ if defer is None or Failure is None:
+ self.skipTest("Need Twisted to run")
+
+
+class TestNotReentrant(NeedsTwistedTestCase):
def test_not_reentrant(self):
# A function decorated as not being re-entrant will raise a
- # ReentryError if it is called while it is running.
+ # _spinner.ReentryError if it is called while it is running.
calls = []
- @not_reentrant
+ @_spinner.not_reentrant
def log_something():
calls.append(None)
if len(calls) < 5:
log_something()
- self.assertThat(log_something, Raises(MatchesException(ReentryError)))
+ self.assertThat(
+ log_something, Raises(MatchesException(_spinner.ReentryError)))
self.assertEqual(1, len(calls))
def test_deeper_stack(self):
calls = []
- @not_reentrant
+ @_spinner.not_reentrant
def g():
calls.append(None)
if len(calls) < 5:
f()
- @not_reentrant
+ @_spinner.not_reentrant
def f():
calls.append(None)
if len(calls) < 5:
g()
- self.assertThat(f, Raises(MatchesException(ReentryError)))
+ self.assertThat(f, Raises(MatchesException(_spinner.ReentryError)))
self.assertEqual(2, len(calls))
-class TestExtractResult(TestCase):
+class TestExtractResult(NeedsTwistedTestCase):
def test_not_fired(self):
- # extract_result raises DeferredNotFired if it's given a Deferred that
- # has not fired.
- self.assertThat(lambda:extract_result(defer.Deferred()),
- Raises(MatchesException(DeferredNotFired)))
+ # _spinner.extract_result raises _spinner.DeferredNotFired if it's
+ # given a Deferred that has not fired.
+ self.assertThat(lambda:_spinner.extract_result(defer.Deferred()),
+ Raises(MatchesException(_spinner.DeferredNotFired)))
def test_success(self):
- # extract_result returns the value of the Deferred if it has fired
- # successfully.
+ # _spinner.extract_result returns the value of the Deferred if it has
+ # fired successfully.
marker = object()
d = defer.succeed(marker)
- self.assertThat(extract_result(d), Equals(marker))
+ self.assertThat(_spinner.extract_result(d), Equals(marker))
def test_failure(self):
- # extract_result raises the failure's exception if it's given a
- # Deferred that is failing.
+ # _spinner.extract_result raises the failure's exception if it's given
+ # a Deferred that is failing.
try:
1/0
except ZeroDivisionError:
f = Failure()
d = defer.fail(f)
- self.assertThat(lambda:extract_result(d),
+ self.assertThat(lambda:_spinner.extract_result(d),
Raises(MatchesException(ZeroDivisionError)))
-class TestTrapUnhandledErrors(TestCase):
+class TestTrapUnhandledErrors(NeedsTwistedTestCase):
def test_no_deferreds(self):
marker = object()
- result, errors = trap_unhandled_errors(lambda: marker)
+ result, errors = _spinner.trap_unhandled_errors(lambda: marker)
self.assertEqual([], errors)
self.assertIs(marker, result)
@@ -105,12 +106,13 @@
f = Failure()
failures.append(f)
defer.fail(f)
- result, errors = trap_unhandled_errors(make_deferred_but_dont_handle)
+ result, errors = _spinner.trap_unhandled_errors(
+ make_deferred_but_dont_handle)
self.assertIs(None, result)
self.assertEqual(failures, [error.failResult for error in errors])
-class TestRunInReactor(TestCase):
+class TestRunInReactor(NeedsTwistedTestCase):
def make_reactor(self):
from twisted.internet import reactor
@@ -119,7 +121,7 @@
def make_spinner(self, reactor=None):
if reactor is None:
reactor = self.make_reactor()
- return Spinner(reactor)
+ return _spinner.Spinner(reactor)
def make_timeout(self):
return 0.01
@@ -157,8 +159,8 @@
# to run_in_reactor.
spinner = self.make_spinner()
self.assertThat(lambda: spinner.run(
- self.make_timeout(), spinner.run, self.make_timeout(), lambda: None),
- Raises(MatchesException(ReentryError)))
+ self.make_timeout(), spinner.run, self.make_timeout(),
+ lambda: None), Raises(MatchesException(_spinner.ReentryError)))
def test_deferred_value_returned(self):
# If the given function returns a Deferred, run_in_reactor returns the
@@ -182,11 +184,12 @@
self.assertEqual(new_hdlrs, map(signal.getsignal, signals))
def test_timeout(self):
- # If the function takes too long to run, we raise a TimeoutError.
+ # If the function takes too long to run, we raise a
+ # _spinner.TimeoutError.
timeout = self.make_timeout()
self.assertThat(
lambda:self.make_spinner().run(timeout, lambda: defer.Deferred()),
- Raises(MatchesException(TimeoutError)))
+ Raises(MatchesException(_spinner.TimeoutError)))
def test_no_junk_by_default(self):
# If the reactor hasn't spun yet, then there cannot be any junk.
@@ -263,7 +266,7 @@
timeout = self.make_timeout()
spinner.run(timeout, reactor.listenTCP, 0, ServerFactory())
self.assertThat(lambda: spinner.run(timeout, lambda: None),
- Raises(MatchesException(StaleJunkError)))
+ Raises(MatchesException(_spinner.StaleJunkError)))
def test_clear_junk_clears_previous_junk(self):
# If 'run' is called and there's still junk in the spinner's junk
@@ -279,7 +282,7 @@
@skipIf(os.name != "posix", "Sending SIGINT with os.kill is posix only")
def test_sigint_raises_no_result_error(self):
- # If we get a SIGINT during a run, we raise NoResultError.
+ # If we get a SIGINT during a run, we raise _spinner.NoResultError.
SIGINT = getattr(signal, 'SIGINT', None)
if not SIGINT:
self.skipTest("SIGINT not available")
@@ -288,19 +291,19 @@
timeout = self.make_timeout()
reactor.callLater(timeout, os.kill, os.getpid(), SIGINT)
self.assertThat(lambda:spinner.run(timeout * 5, defer.Deferred),
- Raises(MatchesException(NoResultError)))
+ Raises(MatchesException(_spinner.NoResultError)))
self.assertEqual([], spinner._clean())
@skipIf(os.name != "posix", "Sending SIGINT with os.kill is posix only")
def test_sigint_raises_no_result_error_second_time(self):
- # If we get a SIGINT during a run, we raise NoResultError. This test
- # is exactly the same as test_sigint_raises_no_result_error, and
- # exists to make sure we haven't futzed with state.
+ # If we get a SIGINT during a run, we raise _spinner.NoResultError.
+ # This test is exactly the same as test_sigint_raises_no_result_error,
+ # and exists to make sure we haven't futzed with state.
self.test_sigint_raises_no_result_error()
@skipIf(os.name != "posix", "Sending SIGINT with os.kill is posix only")
def test_fast_sigint_raises_no_result_error(self):
- # If we get a SIGINT during a run, we raise NoResultError.
+ # If we get a SIGINT during a run, we raise _spinner.NoResultError.
SIGINT = getattr(signal, 'SIGINT', None)
if not SIGINT:
self.skipTest("SIGINT not available")
@@ -309,7 +312,7 @@
timeout = self.make_timeout()
reactor.callWhenRunning(os.kill, os.getpid(), SIGINT)
self.assertThat(lambda:spinner.run(timeout * 5, defer.Deferred),
- Raises(MatchesException(NoResultError)))
+ Raises(MatchesException(_spinner.NoResultError)))
self.assertEqual([], spinner._clean())
@skipIf(os.name != "posix", "Sending SIGINT with os.kill is posix only")
Follow ups