Move internal _is_unittest_unexpected_success_a_failure to "compat" module

Fix #1815
This commit is contained in:
Bruno Oliveira 2016-08-17 22:50:10 -03:00
parent 463e6572c5
commit 3ba475c0f2
3 changed files with 18 additions and 14 deletions

View File

@ -173,6 +173,7 @@ def get_real_func(obj):
obj = obj.func obj = obj.func
return obj return obj
def getfslineno(obj): def getfslineno(obj):
# xxx let decorators etc specify a sane ordering # xxx let decorators etc specify a sane ordering
obj = get_real_func(obj) obj = get_real_func(obj)
@ -182,6 +183,7 @@ def getfslineno(obj):
assert isinstance(fslineno[1], int), obj assert isinstance(fslineno[1], int), obj
return fslineno return fslineno
def getimfunc(func): def getimfunc(func):
try: try:
return func.__func__ return func.__func__
@ -191,6 +193,7 @@ def getimfunc(func):
except AttributeError: except AttributeError:
return func return func
def safe_getattr(object, name, default): def safe_getattr(object, name, default):
""" Like getattr but return default upon any Exception. """ Like getattr but return default upon any Exception.
@ -201,3 +204,15 @@ def safe_getattr(object, name, default):
return getattr(object, name, default) return getattr(object, name, default)
except Exception: except Exception:
return default return default
def _is_unittest_unexpected_success_a_failure():
"""Return if the test suite should fail if a @expectedFailure unittest test PASSES.
From https://docs.python.org/3/library/unittest.html?highlight=unittest#unittest.TestResult.wasSuccessful:
Changed in version 3.4: Returns False if there were any
unexpectedSuccesses from tests marked with the expectedFailure() decorator.
TODO: this should be moved to the "compat" module.
"""
return sys.version_info >= (3, 4)

View File

@ -216,18 +216,6 @@ def check_strict_xfail(pyfuncitem):
pytest.fail('[XPASS(strict)] ' + explanation, pytrace=False) pytest.fail('[XPASS(strict)] ' + explanation, pytrace=False)
def _is_unittest_unexpected_success_a_failure():
"""Return if the test suite should fail if a @expectedFailure unittest test PASSES.
From https://docs.python.org/3/library/unittest.html?highlight=unittest#unittest.TestResult.wasSuccessful:
Changed in version 3.4: Returns False if there were any
unexpectedSuccesses from tests marked with the expectedFailure() decorator.
TODO: this should be moved to the "compat" module.
"""
return sys.version_info >= (3, 4)
@pytest.hookimpl(hookwrapper=True) @pytest.hookimpl(hookwrapper=True)
def pytest_runtest_makereport(item, call): def pytest_runtest_makereport(item, call):
outcome = yield outcome = yield
@ -236,6 +224,7 @@ def pytest_runtest_makereport(item, call):
evalskip = getattr(item, '_evalskip', None) evalskip = getattr(item, '_evalskip', None)
# unitttest special case, see setting of _unexpectedsuccess # unitttest special case, see setting of _unexpectedsuccess
if hasattr(item, '_unexpectedsuccess') and rep.when == "call": if hasattr(item, '_unexpectedsuccess') and rep.when == "call":
from _pytest.compat import _is_unittest_unexpected_success_a_failure
if item._unexpectedsuccess: if item._unexpectedsuccess:
rep.longrepr = "Unexpected success: {0}".format(item._unexpectedsuccess) rep.longrepr = "Unexpected success: {0}".format(item._unexpectedsuccess)
else: else:

View File

@ -419,7 +419,7 @@ class TestTrialUnittest:
def test_method(self): def test_method(self):
pass pass
""") """)
from _pytest.skipping import _is_unittest_unexpected_success_a_failure from _pytest.compat import _is_unittest_unexpected_success_a_failure
should_fail = _is_unittest_unexpected_success_a_failure() should_fail = _is_unittest_unexpected_success_a_failure()
result = testdir.runpytest("-rxs") result = testdir.runpytest("-rxs")
result.stdout.fnmatch_lines_random([ result.stdout.fnmatch_lines_random([
@ -629,7 +629,7 @@ def test_unittest_expected_failure_for_passing_test_is_fail(testdir, runner):
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()
""") """)
from _pytest.skipping import _is_unittest_unexpected_success_a_failure from _pytest.compat import _is_unittest_unexpected_success_a_failure
should_fail = _is_unittest_unexpected_success_a_failure() should_fail = _is_unittest_unexpected_success_a_failure()
if runner == 'pytest': if runner == 'pytest':
result = testdir.runpytest("-rxX") result = testdir.runpytest("-rxX")