Merge lp:~statik/testtools/skip-decorators into lp:~testtools-committers/testtools/trunk

Proposed by Elliot Murphy
Status: Superseded
Proposed branch: lp:~statik/testtools/skip-decorators
Merge into: lp:~testtools-committers/testtools/trunk
Diff against target: None lines
To merge this branch: bzr merge lp:~statik/testtools/skip-decorators
Reviewer Review Type Date Requested Status
Robert Collins Needs Fixing
Jonathan Lange Pending
Review via email: mp+5405@code.launchpad.net

This proposal has been superseded by a proposal from 2009-06-16.

To post a comment you must log in.
Revision history for this message
Elliot Murphy (statik) wrote :

Add skip, skipIf, and skipUnless decorators to make it easy to write unit tests which are forward-compatible with the skipping support in python2.7 stdlib.

lp:~statik/testtools/skip-decorators updated
16. By Elliot Murphy

Merged trunk.

Revision history for this message
Elliot Murphy (statik) wrote :

Merged with trunk to pick up the latest stuff from Robert. Rev16 of this branch is what is going through REVU now, to hopefully go into Karmic when the archives open.

Revision history for this message
Robert Collins (lifeless) wrote :

I did it by mail, it failed. so here is:
 status needsfixing

        @This has a test for the skip decorator, but could probably use some
        cleverness with clone_test_with_new_id in order to generate some
        tests for all three decorators.

        see testscenarios for glue to do this with much ease.

        I hope to get a patch into 2.7 to make skips take closures not evaluated
        conditions. Or something. Bah!

        Needs info in the manual about this.

        -Rob

review: Needs Fixing
Revision history for this message
Jonathan Lange (jml) wrote :

Sorry about the delay on this patch -- what's the story, is it still something we want to land?

Revision history for this message
Elliot Murphy (statik) wrote :

> Sorry about the delay on this patch -- what's the story, is it still something
> we want to land?

Yes please, I'd like to see it land. I can work on adding some other tests tonight, but I'm hesitant to add a dependency on testscenarios.

Revision history for this message
Elliot Murphy (statik) wrote :

> > Sorry about the delay on this patch -- what's the story, is it still
> something
> > we want to land?
>
> Yes please, I'd like to see it land. I can work on adding some other tests
> tonight, but I'm hesitant to add a dependency on testscenarios.

Oops, I actually already added the missing tests a while ago. I'm going to resubmit this merge proposal so the diff will be regenerated.

lp:~statik/testtools/skip-decorators updated
17. By Elliot Murphy

Reformatted imports per code review comments from jml.

Unmerged revisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'testtools/__init__.py'
--- testtools/__init__.py 2008-10-04 03:59:24 +0000
+++ testtools/__init__.py 2009-04-09 17:24:49 +0000
@@ -8,8 +8,12 @@
8 'MultiTestResult',8 'MultiTestResult',
9 'TestCase',9 'TestCase',
10 'TestResult',10 'TestResult',
11 'skip',
12 'skipIf',
13 'skipUnless',
11 ]14 ]
1215
13from testtools.testcase import TestCase, clone_test_with_new_id16from testtools.testcase import (TestCase, clone_test_with_new_id,
17 skip, skipIf, skipUnless)
14from testtools.testresult import MultiTestResult, TestResult18from testtools.testresult import MultiTestResult, TestResult
15from testtools.utils import iterate_tests19from testtools.utils import iterate_tests
1620
=== modified file 'testtools/testcase.py'
--- testtools/testcase.py 2009-03-05 04:38:11 +0000
+++ testtools/testcase.py 2009-04-09 17:24:49 +0000
@@ -6,9 +6,13 @@
6__all__ = [6__all__ = [
7 'change_test_id',7 'change_test_id',
8 'TestCase',8 'TestCase',
9 'skip',
10 'skipIf',
11 'skipUnless',
9 ]12 ]
1013
11from copy import deepcopy14from copy import deepcopy
15import functools
12import unittest16import unittest
1317
1418
@@ -199,3 +203,35 @@
199 newTest.id = lambda: new_id203 newTest.id = lambda: new_id
200 return newTest204 return newTest
201205
206def skip(reason):
207 """A decorator to skip unit tests.
208
209 This is just syntactic sugar so users don't have to change any of their
210 unit tests in order to migrate to python 2.7, which provides the
211 @unittest.skip decorator.
212 """
213 def decorator(test_item):
214 @functools.wraps(test_item)
215 def skip_wrapper(*args, **kwargs):
216 raise TestCase.skipException(reason)
217 return skip_wrapper
218 return decorator
219
220
221def skipIf(condition, reason):
222 """Skip a test if the condition is true."""
223 if condition:
224 return skip(reason)
225 def _id(obj):
226 return obj
227 return _id
228
229
230def skipUnless(condition, reason):
231 """Skip a test unless the condition is true."""
232 if not condition:
233 return skip(reason)
234 def _id(obj):
235 return obj
236 return _id
237
202238
=== modified file 'testtools/tests/test_testtools.py'
--- testtools/tests/test_testtools.py 2009-02-28 04:22:53 +0000
+++ testtools/tests/test_testtools.py 2009-04-09 17:34:30 +0000
@@ -3,7 +3,8 @@
3"""Tests for extensions to the base test library."""3"""Tests for extensions to the base test library."""
44
5import unittest5import unittest
6from testtools import TestCase, clone_test_with_new_id6from testtools import (TestCase, clone_test_with_new_id,
7 skip, skipIf, skipUnless)
7from testtools.tests.helpers import LoggingResult8from testtools.tests.helpers import LoggingResult
89
910
@@ -428,6 +429,38 @@
428 test.run(result)429 test.run(result)
429 self.assertEqual(1, len(result.errors))430 self.assertEqual(1, len(result.errors))
430431
432 def test_skip_decorator(self):
433 class SkippingTest(TestCase):
434 @skip("skipping this test")
435 def test_that_is_decorated_with_skip(self):
436 self.fail()
437 result = unittest.TestResult()
438 test = SkippingTest("test_that_is_decorated_with_skip")
439 test.run(result)
440 self.assertEqual(1, len(result.errors))
441
442
443 def test_skipIf_decorator(self):
444 class SkippingTest(TestCase):
445 @skipIf(True, "skipping this test")
446 def test_that_is_decorated_with_skipIf(self):
447 self.fail()
448 result = unittest.TestResult()
449 test = SkippingTest("test_that_is_decorated_with_skipIf")
450 test.run(result)
451 self.assertEqual(1, len(result.errors))
452
453
454 def test_skipUnless_decorator(self):
455 class SkippingTest(TestCase):
456 @skipUnless(False, "skipping this test")
457 def test_that_is_decorated_with_skipUnless(self):
458 self.fail()
459 result = unittest.TestResult()
460 test = SkippingTest("test_that_is_decorated_with_skipUnless")
461 test.run(result)
462 self.assertEqual(1, len(result.errors))
463
431464
432def test_suite():465def test_suite():
433 from unittest import TestLoader466 from unittest import TestLoader

Subscribers

People subscribed via source and target branches