nose2 icon indicating copy to clipboard operation
nose2 copied to clipboard

SkipTest raised inside setupClass treated as error

Open Link512 opened this issue 8 years ago • 6 comments

virtualenv python version: 3.6.2 nose2 version: 0.7.2 unittest2 version: 1.1.0

snippet:

import unittest2

class Failing(unittest2.TestCase):

    @classmethod
    def setUpClass(cls):

        raise unittest2.SkipTest

    def testWillBeIgnored(self):

        self.assertTrue(1)

Expected behaviour: Test case is skipped Actual behaviour: SkipTest is treated like actual error. See below:

nose2
E
======================================================================
ERROR: _ErrorHolder
----------------------------------------------------------------------
Traceback (most recent call last):
  File "[...]/test_nose/test_failure.py", line 8, in setUpClass
    raise unittest2.SkipTest
unittest2.case.SkipTest

----------------------------------------------------------------------
Ran 0 tests in 0.000s

Link512 avatar Nov 16 '17 18:11 Link512

Thanks for reporting. I assume this worked fine under 0.6.5? Maybe pin there for now.

This functionality should get tested here: https://github.com/nose-devs/nose2/blob/7928e015873a7dc22eb5d0693ae34a52dd8141f8/nose2/tests/functional/support/scenario/tests_in_package/pkg1/test/test_things.py#L23 (but with unittest not unittest2)

katrinabrock avatar Nov 16 '17 20:11 katrinabrock

Yes, with 0.6.5 it works fine.

Link512 avatar Nov 17 '17 07:11 Link512

Able to reproduce on python version 2.7

katrinabrock avatar Nov 18 '17 06:11 katrinabrock

Unsurprisingly, this is where the bug was introduced: https://github.com/nose-devs/nose2/commit/19822c9845ba37fa51e0bc29016c57254957d968

katrinabrock avatar Nov 18 '17 07:11 katrinabrock

I have more information. In 0.6.5, this type of construct did not properly skip the test if SkipTest from unittest was used. Running this snippet with different versions of nose2 demonstrates this behavior

import unittest
import unittest2


class SkipUnitTest(unittest.TestCase):

    @classmethod
    def setUpClass(cls):

        raise unittest.SkipTest('UnitTest, skipped in 0.7.X')

    def testWillBeIgnored(self):

        self.assertTrue(1)


class SkipUnitTest2(unittest2.TestCase):

    @classmethod
    def setUpClass(cls):

        raise unittest2.SkipTest('UnitTest2, skipped in 0.6.5')

    def testWillBeIgnored(self):

        self.assertTrue(1)

Python 2.7.13

Switching between unittest and unittest2 here

https://github.com/nose-devs/nose2/blob/master/nose2/loader.py#L30

toggles that behavior.

Haven't figured out why or best way to support both unittest.SkipTest and unittest2.SkipTest

katrinabrock avatar Nov 18 '17 21:11 katrinabrock

Ok my joke was wrong... Yeah. It looks like and interesting problem :(.

ptthiem avatar Nov 19 '17 00:11 ptthiem