try to better handle @unittest.expectedFailure decorator
This commit is contained in:
parent
e643e99586
commit
58933aac2a
|
@ -3,6 +3,8 @@ Changese between 2.2.3 and ...
|
||||||
|
|
||||||
- fix issue 126: correctly match all invalid xml characters for junitxml
|
- fix issue 126: correctly match all invalid xml characters for junitxml
|
||||||
binary escape
|
binary escape
|
||||||
|
- fix issue with unittest: now @unittest.expectedFailure markers should
|
||||||
|
be processed correctly (you can also use @pytest.mark markers)
|
||||||
- document integration with the extended distribute/setuptools test commands
|
- document integration with the extended distribute/setuptools test commands
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
#
|
#
|
||||||
__version__ = '2.2.4.dev1'
|
__version__ = '2.2.4.dev2'
|
||||||
|
|
|
@ -132,6 +132,14 @@ def check_xfail_no_run(item):
|
||||||
def pytest_runtest_makereport(__multicall__, item, call):
|
def pytest_runtest_makereport(__multicall__, item, call):
|
||||||
if not isinstance(item, pytest.Function):
|
if not isinstance(item, pytest.Function):
|
||||||
return
|
return
|
||||||
|
# unitttest special case, see setting of _unexpectedsuccess
|
||||||
|
if hasattr(item, '_unexpectedsuccess'):
|
||||||
|
rep = __multicall__.execute()
|
||||||
|
if rep.when == "call":
|
||||||
|
# we need to translate into how py.test encodes xpass
|
||||||
|
rep.keywords['xfail'] = "reason: " + item._unexpectedsuccess
|
||||||
|
rep.outcome = "failed"
|
||||||
|
return rep
|
||||||
if not (call.excinfo and
|
if not (call.excinfo and
|
||||||
call.excinfo.errisinstance(py.test.xfail.Exception)):
|
call.excinfo.errisinstance(py.test.xfail.Exception)):
|
||||||
evalxfail = getattr(item, '_evalxfail', None)
|
evalxfail = getattr(item, '_evalxfail', None)
|
||||||
|
|
|
@ -91,22 +91,28 @@ class TestCaseFunction(pytest.Function):
|
||||||
self._addexcinfo(rawexcinfo)
|
self._addexcinfo(rawexcinfo)
|
||||||
def addFailure(self, testcase, rawexcinfo):
|
def addFailure(self, testcase, rawexcinfo):
|
||||||
self._addexcinfo(rawexcinfo)
|
self._addexcinfo(rawexcinfo)
|
||||||
|
|
||||||
def addSkip(self, testcase, reason):
|
def addSkip(self, testcase, reason):
|
||||||
try:
|
try:
|
||||||
pytest.skip(reason)
|
pytest.skip(reason)
|
||||||
except pytest.skip.Exception:
|
except pytest.skip.Exception:
|
||||||
self._addexcinfo(sys.exc_info())
|
self._addexcinfo(sys.exc_info())
|
||||||
def addExpectedFailure(self, testcase, rawexcinfo, reason):
|
|
||||||
|
def addExpectedFailure(self, testcase, rawexcinfo, reason=""):
|
||||||
try:
|
try:
|
||||||
pytest.xfail(str(reason))
|
pytest.xfail(str(reason))
|
||||||
except pytest.xfail.Exception:
|
except pytest.xfail.Exception:
|
||||||
self._addexcinfo(sys.exc_info())
|
self._addexcinfo(sys.exc_info())
|
||||||
def addUnexpectedSuccess(self, testcase, reason):
|
|
||||||
pass
|
def addUnexpectedSuccess(self, testcase, reason=""):
|
||||||
|
self._unexpectedsuccess = reason
|
||||||
|
|
||||||
def addSuccess(self, testcase):
|
def addSuccess(self, testcase):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def stopTest(self, testcase):
|
def stopTest(self, testcase):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def runtest(self):
|
def runtest(self):
|
||||||
self._testcase(result=self)
|
self._testcase(result=self)
|
||||||
|
|
||||||
|
|
2
setup.py
2
setup.py
|
@ -24,7 +24,7 @@ def main():
|
||||||
name='pytest',
|
name='pytest',
|
||||||
description='py.test: simple powerful testing with Python',
|
description='py.test: simple powerful testing with Python',
|
||||||
long_description = long_description,
|
long_description = long_description,
|
||||||
version='2.2.4.dev1',
|
version='2.2.4.dev2',
|
||||||
url='http://pytest.org',
|
url='http://pytest.org',
|
||||||
license='MIT license',
|
license='MIT license',
|
||||||
platforms=['unix', 'linux', 'osx', 'cygwin', 'win32'],
|
platforms=['unix', 'linux', 'osx', 'cygwin', 'win32'],
|
||||||
|
|
|
@ -459,3 +459,24 @@ def test_unittest_typerror_traceback(testdir):
|
||||||
result = testdir.runpytest()
|
result = testdir.runpytest()
|
||||||
assert "TypeError" in result.stdout.str()
|
assert "TypeError" in result.stdout.str()
|
||||||
assert result.ret == 1
|
assert result.ret == 1
|
||||||
|
|
||||||
|
@pytest.mark.skipif("sys.version_info < (2,7)")
|
||||||
|
def test_unittest_unexpected_failure(testdir):
|
||||||
|
testdir.makepyfile("""
|
||||||
|
import unittest
|
||||||
|
class MyTestCase(unittest.TestCase):
|
||||||
|
@unittest.expectedFailure
|
||||||
|
def test_func1(self):
|
||||||
|
assert 0
|
||||||
|
@unittest.expectedFailure
|
||||||
|
def test_func2(self):
|
||||||
|
assert 1
|
||||||
|
""")
|
||||||
|
result = testdir.runpytest("-rxX")
|
||||||
|
result.stdout.fnmatch_lines([
|
||||||
|
"*XFAIL*MyTestCase*test_func1*",
|
||||||
|
"*XPASS*MyTestCase*test_func2*",
|
||||||
|
"*1 xfailed*1 xpass*",
|
||||||
|
])
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue