|
30 | 30 | from _pytest.python import PyCollector
|
31 | 31 | from _pytest.runner import CallInfo
|
32 | 32 | from _pytest.skipping import skipped_by_mark_key
|
33 |
| -from _pytest.skipping import unexpectedsuccess_key |
34 | 33 |
|
35 | 34 | if TYPE_CHECKING:
|
36 | 35 | import unittest
|
| 36 | + import twisted.trial.unittest |
37 | 37 |
|
38 | 38 | from _pytest.fixtures import _Scope
|
39 | 39 |
|
@@ -273,25 +273,25 @@ def addExpectedFailure(
|
273 | 273 | self._addexcinfo(sys.exc_info())
|
274 | 274 |
|
275 | 275 | def addUnexpectedSuccess(
|
276 |
| - self, testcase: "unittest.TestCase", reason: str = "" |
| 276 | + self, |
| 277 | + testcase: "unittest.TestCase", |
| 278 | + reason: Optional["twisted.trial.unittest.Todo"] = None, |
277 | 279 | ) -> None:
|
278 |
| - self._store[unexpectedsuccess_key] = reason |
| 280 | + msg = "Unexpected success" |
| 281 | + if reason: |
| 282 | + msg += f": {reason.reason}" |
| 283 | + # Preserve unittest behaviour - fail the test |
| 284 | + try: |
| 285 | + fail(msg, pytrace=False) |
| 286 | + except fail.Exception: |
| 287 | + self._addexcinfo(sys.exc_info()) |
279 | 288 |
|
280 | 289 | def addSuccess(self, testcase: "unittest.TestCase") -> None:
|
281 | 290 | pass
|
282 | 291 |
|
283 | 292 | def stopTest(self, testcase: "unittest.TestCase") -> None:
|
284 | 293 | pass
|
285 | 294 |
|
286 |
| - def _expecting_failure(self, test_method) -> bool: |
287 |
| - """Return True if the given unittest method (or the entire class) is marked |
288 |
| - with @expectedFailure.""" |
289 |
| - expecting_failure_method = getattr( |
290 |
| - test_method, "__unittest_expecting_failure__", False |
291 |
| - ) |
292 |
| - expecting_failure_class = getattr(self, "__unittest_expecting_failure__", False) |
293 |
| - return bool(expecting_failure_class or expecting_failure_method) |
294 |
| - |
295 | 295 | def runtest(self) -> None:
|
296 | 296 | from _pytest.debugging import maybe_wrap_pytest_function_for_tracing
|
297 | 297 |
|
|
0 commit comments