Fix issue where using the skip* family of decorators still ran the setUp and tearDown test methods. #103

Merged
merged 1 commit into from Sep 1, 2014

Conversation

Projects
None yet
2 participants
Member

thomir commented Sep 1, 2014

This closes #86.

I make the testtools skip decorator set the unittest_skip attribute on test methods, which makes them compatible with the unittest functions of the same name.

I then change RunTest._run_core to look for that attribute and not run setUp if it's present.

Owner

rbtcollins commented Sep 1, 2014

Also CI failed - you'll need to fix that :)

testtools/runtest.py
@@ -112,6 +112,10 @@ def _run_prepared_result(self, result):
def _run_core(self):
"""Run the user supplied test code."""
+ if getattr(self.case._get_test_method(), '__unittest_skip__', False):
+ self.result.addSuccess(self.case, details=self.case.getDetails())
@rbtcollins

rbtcollins Sep 1, 2014

Owner

Is Success the right result for a skip?

@thomir

thomir Sep 1, 2014

Member

I think so. As far as I can make out, this is what it was doing before, and there are explicit tests for the 2.6 and 2.7 result objects (see test_testcase.py:1303-1364).

testtools/tests/test_testcase.py
+
+ def __init__(self, *args):
+ super(SkippingTest, self).__init__(*args)
+ self.setup_ran = False
@rbtcollins

rbtcollins Sep 1, 2014

Owner

btw having the default of False on the class was fine, you don't need the init - you just can't store it there per-test.

@thomir

thomir Sep 1, 2014

Member

doh! that was dumb...

testtools/tests/test_testcase.py
+ test = SkippingTest('test_skipped')
+ result = test.run()
+ self.assertTrue(result.wasSuccessful())
+ self.assertFalse(test.setup_ran)
@rbtcollins

rbtcollins Sep 1, 2014

Owner

I suspect we need to check this registered as a skip too :)

testtools/tests/test_testcase.py
+ unittest.skipIf(True, "Skip this test")
+ )
+
+ @skipIf(sys.version < '2.7', "no unittest.skipUnless in Py2.6")
@rbtcollins

rbtcollins Sep 1, 2014

Owner

You might like to factor this out into a constant

require_27 = skipIf(...)

...
@require_27

rbtcollins added a commit that referenced this pull request Sep 1, 2014

Merge pull request #103 from thomir/fix-skip-decorator
Fix issue where using the skip* family of decorators still ran the setUp and tearDown test methods.

@rbtcollins rbtcollins merged commit b04e714 into testing-cabal:master Sep 1, 2014

1 check passed

continuous-integration/travis-ci The Travis CI build passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment