skip/skipIf/skipUnless don't work as class decorators

Bug #1529047 reported by Jonathan Lange
14
This bug affects 3 people
Affects Status Importance Assigned to Milestone
testtools
Fix Committed
Wishlist
Zane Bitter

Bug Description

If you want to skip all the tests in a class:

    class FooTests(TestCase):
        @skipIf(True, "Reason")
        def setUp(self):
            super(FooTests, self).setUp()

This is a bit tedious.

I think I want a class decorator.

Jonathan Lange (jml)
Changed in testtools:
status: New → Triaged
importance: Undecided → Wishlist
Revision history for this message
Robert Collins (lifeless) wrote :

I thought the decorators did work on classes? They do in unittest which we largely derive from.

Revision history for this message
Jonathan Lange (jml) wrote : Re: [Bug 1529047] Re: Skipping all tests in a class is awkward

They *do* work on unittest but they don't work from testtools:

## testtools + skipping

```python
import unittest
from testtools import skipIf

@skipIf(True, 'Ha!')
class FooTests(unittest.TestCase):

    def setUp(self):
        pass

    def test_foo(self):
        print 'foo'

    def test_bar(self):
        print 'bar'

unittest.main()
```

Result: Ran 0 tests in 0.000s

## testtools + no skipping

```python
import unittest
from testtools import skipIf

@skipIf(False, 'Ha!')
class FooTests(unittest.TestCase):

    def setUp(self):
        pass

    def test_foo(self):
        print 'foo'

    def test_bar(self):
        print 'bar'

unittest.main()
```

Result:
bar
.foo
.
----------------------------------------------------------------------
Ran 2 tests in 0.000s

## unittest + skipping

```python
import unittest
from unittest import skipIf

@skipIf(True, 'Ha!')
class FooTests(unittest.TestCase):

    def setUp(self):
        pass

    def test_foo(self):
        print 'foo'

    def test_bar(self):
        print 'bar'

unittest.main()
```

Result:
ss
----------------------------------------------------------------------
Ran 2 tests in 0.000s

## unittest + no skipping

```python
import unittest
from unittest import skipIf

@skipIf(False, 'Ha!')
class FooTests(unittest.TestCase):

    def setUp(self):
        pass

    def test_foo(self):
        print 'foo'

    def test_bar(self):
        print 'bar'

unittest.main()
```

Result:

```
bar
.foo
.
----------------------------------------------------------------------
Ran 2 tests in 0.000s
```

On Thu, 24 Dec 2015 at 19:25 Robert Collins <email address hidden>
wrote:

> I thought the decorators did work on classes? They do in unittest which
> we largely derive from.
>
> --
> You received this bug notification because you are subscribed to the bug
> report.
> https://bugs.launchpad.net/bugs/1529047
>
> Title:
> Skipping all tests in a class is awkward
>
> To manage notifications about this bug go to:
> https://bugs.launchpad.net/testtools/+bug/1529047/+subscriptions
>

Revision history for this message
Jonathan Lange (jml) wrote : Re: Skipping all tests in a class is awkward
Revision history for this message
Zane Bitter (zaneb) wrote :

Pull request: https://github.com/testing-cabal/testtools/pull/268

I'd also argue that this is bug and not merely a wishlist item, since it prevents testtools from being used as a drop-in replacement for unittest.

Changed in testtools:
assignee: nobody → Zane Bitter (zaneb)
status: Triaged → In Progress
Zane Bitter (zaneb)
summary: - Skipping all tests in a class is awkward
+ skip/skipIf/skipUnless don't work as class decorators
Zane Bitter (zaneb)
Changed in testtools:
status: In Progress → Fix Committed
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.