unittest: add clarifying comment on unittest.SkipTest -> pytest.skip code

I was tempted to remove it, until I figured out why it was there.
This commit is contained in:
Ran Benita 2021-01-14 17:05:01 +02:00
parent addbd3161e
commit 096bae6c68
1 changed files with 4 additions and 1 deletions

View File

@ -343,6 +343,10 @@ def pytest_runtest_makereport(item: Item, call: CallInfo[None]) -> None:
except AttributeError:
pass
# Convert unittest.SkipTest to pytest.skip.
# This is actually only needed for nose, which reuses unittest.SkipTest for
# its own nose.SkipTest. For unittest TestCases, SkipTest is already
# handled internally, and doesn't reach here.
unittest = sys.modules.get("unittest")
if (
unittest
@ -350,7 +354,6 @@ def pytest_runtest_makereport(item: Item, call: CallInfo[None]) -> None:
and isinstance(call.excinfo.value, unittest.SkipTest) # type: ignore[attr-defined]
):
excinfo = call.excinfo
# Let's substitute the excinfo with a pytest.skip one.
call2 = CallInfo[None].from_call(
lambda: pytest.skip(str(excinfo.value)), call.when
)