From 3ba475c0f25b57c25f594429186b873c2c7fdbbe Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Wed, 17 Aug 2016 22:50:10 -0300 Subject: [PATCH] Move internal _is_unittest_unexpected_success_a_failure to "compat" module Fix #1815 --- _pytest/compat.py | 15 +++++++++++++++ _pytest/skipping.py | 13 +------------ testing/test_unittest.py | 4 ++-- 3 files changed, 18 insertions(+), 14 deletions(-) diff --git a/_pytest/compat.py b/_pytest/compat.py index 1a2f1e24a..23e3b8b92 100644 --- a/_pytest/compat.py +++ b/_pytest/compat.py @@ -173,6 +173,7 @@ def get_real_func(obj): obj = obj.func return obj + def getfslineno(obj): # xxx let decorators etc specify a sane ordering obj = get_real_func(obj) @@ -182,6 +183,7 @@ def getfslineno(obj): assert isinstance(fslineno[1], int), obj return fslineno + def getimfunc(func): try: return func.__func__ @@ -191,6 +193,7 @@ def getimfunc(func): except AttributeError: return func + def safe_getattr(object, name, default): """ Like getattr but return default upon any Exception. @@ -201,3 +204,15 @@ def safe_getattr(object, name, default): return getattr(object, name, default) except Exception: 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) \ No newline at end of file diff --git a/_pytest/skipping.py b/_pytest/skipping.py index 8d93dc4c3..2f000b7b9 100644 --- a/_pytest/skipping.py +++ b/_pytest/skipping.py @@ -216,18 +216,6 @@ def check_strict_xfail(pyfuncitem): 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) def pytest_runtest_makereport(item, call): outcome = yield @@ -236,6 +224,7 @@ def pytest_runtest_makereport(item, call): evalskip = getattr(item, '_evalskip', None) # unitttest special case, see setting of _unexpectedsuccess if hasattr(item, '_unexpectedsuccess') and rep.when == "call": + from _pytest.compat import _is_unittest_unexpected_success_a_failure if item._unexpectedsuccess: rep.longrepr = "Unexpected success: {0}".format(item._unexpectedsuccess) else: diff --git a/testing/test_unittest.py b/testing/test_unittest.py index ba34e093a..b6be95fa5 100644 --- a/testing/test_unittest.py +++ b/testing/test_unittest.py @@ -419,7 +419,7 @@ class TestTrialUnittest: def test_method(self): 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() result = testdir.runpytest("-rxs") result.stdout.fnmatch_lines_random([ @@ -629,7 +629,7 @@ def test_unittest_expected_failure_for_passing_test_is_fail(testdir, runner): if __name__ == '__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() if runner == 'pytest': result = testdir.runpytest("-rxX")