[issue34596] [unittest] raise error if @skip is used with an argument that looks like a test method
Zachary Ware
report at bugs.python.org
Thu Sep 6 10:25:26 EDT 2018
Zachary Ware <zachary.ware at gmail.com> added the comment:
It could be interesting to enable uncalled `skip` by setting a default reason of "Unconditional skip" when the argument is a function.
Do note that decorating with an uncalled `skip` does actually work to skip the test currently, but the test is marked as success rather than skipped (see example pasted below). For this reason, I don't think we should turn it into an error in maintenance releases, as anyone using this accidentally will suddenly have many failing tests.
$ cat test.py
from unittest import TestCase, skip
class Test(TestCase):
def test_good(self):
self.assertTrue(1.0)
def test_bad(self):
self.assertFalse(1.0)
@skip
def test_bad_skip(self):
self.assertFalse(1.0)
@skip('always skipped')
def test_good_skip(self):
self.assertFalse(1.0)
$ ./python.exe -m unittest test.py -v
test_bad (test.Test) ... FAIL
test_bad_skip (test.Test) ... ok
test_good (test.Test) ... ok
test_good_skip (test.Test) ... skipped 'always skipped'
======================================================================
FAIL: test_bad (test.Test)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/.../test.py", line 10, in test_bad
self.assertFalse(1.0)
AssertionError: 1.0 is not false
----------------------------------------------------------------------
Ran 4 tests in 0.002s
FAILED (failures=1, skipped=1)
----------
nosy: +zach.ware
versions: -Python 3.4, Python 3.5
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue34596>
_______________________________________
More information about the Python-bugs-list
mailing list