Skip to content

Commit 3ba475c

Browse files
committed
Move internal _is_unittest_unexpected_success_a_failure to "compat" module
Fix #1815
1 parent 463e657 commit 3ba475c

File tree

3 files changed

+18
-14
lines changed

3 files changed

+18
-14
lines changed

_pytest/compat.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ def get_real_func(obj):
173173
obj = obj.func
174174
return obj
175175

176+
176177
def getfslineno(obj):
177178
# xxx let decorators etc specify a sane ordering
178179
obj = get_real_func(obj)
@@ -182,6 +183,7 @@ def getfslineno(obj):
182183
assert isinstance(fslineno[1], int), obj
183184
return fslineno
184185

186+
185187
def getimfunc(func):
186188
try:
187189
return func.__func__
@@ -191,6 +193,7 @@ def getimfunc(func):
191193
except AttributeError:
192194
return func
193195

196+
194197
def safe_getattr(object, name, default):
195198
""" Like getattr but return default upon any Exception.
196199
@@ -201,3 +204,15 @@ def safe_getattr(object, name, default):
201204
return getattr(object, name, default)
202205
except Exception:
203206
return default
207+
208+
209+
def _is_unittest_unexpected_success_a_failure():
210+
"""Return if the test suite should fail if a @expectedFailure unittest test PASSES.
211+
212+
From https://docs.python.org/3/library/unittest.html?highlight=unittest#unittest.TestResult.wasSuccessful:
213+
Changed in version 3.4: Returns False if there were any
214+
unexpectedSuccesses from tests marked with the expectedFailure() decorator.
215+
216+
TODO: this should be moved to the "compat" module.
217+
"""
218+
return sys.version_info >= (3, 4)

_pytest/skipping.py

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -216,18 +216,6 @@ def check_strict_xfail(pyfuncitem):
216216
pytest.fail('[XPASS(strict)] ' + explanation, pytrace=False)
217217

218218

219-
def _is_unittest_unexpected_success_a_failure():
220-
"""Return if the test suite should fail if a @expectedFailure unittest test PASSES.
221-
222-
From https://docs.python.org/3/library/unittest.html?highlight=unittest#unittest.TestResult.wasSuccessful:
223-
Changed in version 3.4: Returns False if there were any
224-
unexpectedSuccesses from tests marked with the expectedFailure() decorator.
225-
226-
TODO: this should be moved to the "compat" module.
227-
"""
228-
return sys.version_info >= (3, 4)
229-
230-
231219
@pytest.hookimpl(hookwrapper=True)
232220
def pytest_runtest_makereport(item, call):
233221
outcome = yield
@@ -236,6 +224,7 @@ def pytest_runtest_makereport(item, call):
236224
evalskip = getattr(item, '_evalskip', None)
237225
# unitttest special case, see setting of _unexpectedsuccess
238226
if hasattr(item, '_unexpectedsuccess') and rep.when == "call":
227+
from _pytest.compat import _is_unittest_unexpected_success_a_failure
239228
if item._unexpectedsuccess:
240229
rep.longrepr = "Unexpected success: {0}".format(item._unexpectedsuccess)
241230
else:

testing/test_unittest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ def setup_class(cls):
419419
def test_method(self):
420420
pass
421421
""")
422-
from _pytest.skipping import _is_unittest_unexpected_success_a_failure
422+
from _pytest.compat import _is_unittest_unexpected_success_a_failure
423423
should_fail = _is_unittest_unexpected_success_a_failure()
424424
result = testdir.runpytest("-rxs")
425425
result.stdout.fnmatch_lines_random([
@@ -629,7 +629,7 @@ def test_passing_test_is_fail(self):
629629
if __name__ == '__main__':
630630
unittest.main()
631631
""")
632-
from _pytest.skipping import _is_unittest_unexpected_success_a_failure
632+
from _pytest.compat import _is_unittest_unexpected_success_a_failure
633633
should_fail = _is_unittest_unexpected_success_a_failure()
634634
if runner == 'pytest':
635635
result = testdir.runpytest("-rxX")

0 commit comments

Comments
 (0)