SkipTest raised inside setupClass treated as error
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
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)
Yes, with 0.6.5 it works fine.
Able to reproduce on python version 2.7
Unsurprisingly, this is where the bug was introduced: https://github.com/nose-devs/nose2/commit/19822c9845ba37fa51e0bc29016c57254957d968
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
Ok my joke was wrong... Yeah. It looks like and interesting problem :(.