summaryrefslogtreecommitdiff
path: root/src/_pytest/unittest.py
diff options
context:
space:
mode:
authorRan Benita <ran@unusedvar.com>2020-07-14 10:55:17 +0300
committerRan Benita <ran@unusedvar.com>2020-08-01 17:14:37 +0300
commit0242de4f5651818379bc0ff6326c97565a20a0f1 (patch)
treecbfc4c8dea3cb5b6ea3f355e4681927c2ea64e81 /src/_pytest/unittest.py
parent6882c0368b14e979642fdec0721a9922ba568074 (diff)
downloadpytest-0242de4f5651818379bc0ff6326c97565a20a0f1.tar.gz
Format docstrings in a consistent style
Diffstat (limited to 'src/_pytest/unittest.py')
-rw-r--r--src/_pytest/unittest.py42
1 files changed, 21 insertions, 21 deletions
diff --git a/src/_pytest/unittest.py b/src/_pytest/unittest.py
index 782a5c369..75c53a552 100644
--- a/src/_pytest/unittest.py
+++ b/src/_pytest/unittest.py
@@ -1,4 +1,4 @@
-""" discovery and running of std-library "unittest" style tests. """
+"""Discover and run std-library "unittest" style tests."""
import sys
import traceback
import types
@@ -46,7 +46,7 @@ if TYPE_CHECKING:
def pytest_pycollect_makeitem(
collector: PyCollector, name: str, obj: object
) -> Optional["UnitTestCase"]:
- # has unittest been imported and is obj a subclass of its TestCase?
+ # Has unittest been imported and is obj a subclass of its TestCase?
try:
ut = sys.modules["unittest"]
# Type ignored because `ut` is an opaque module.
@@ -54,14 +54,14 @@ def pytest_pycollect_makeitem(
return None
except Exception:
return None
- # yes, so let's collect it
+ # Yes, so let's collect it.
item = UnitTestCase.from_parent(collector, name=name, obj=obj) # type: UnitTestCase
return item
class UnitTestCase(Class):
- # marker for fixturemanger.getfixtureinfo()
- # to declare that our children do not support funcargs
+ # Marker for fixturemanger.getfixtureinfo()
+ # to declare that our children do not support funcargs.
nofuncargs = True
def collect(self) -> Iterable[Union[Item, Collector]]:
@@ -97,7 +97,7 @@ class UnitTestCase(Class):
def _inject_setup_teardown_fixtures(self, cls: type) -> None:
"""Injects a hidden auto-use fixture to invoke setUpClass/setup_method and corresponding
- teardown functions (#517)"""
+ teardown functions (#517)."""
class_fixture = _make_xunit_fixture(
cls, "setUpClass", "tearDownClass", scope="class", pass_self=False
)
@@ -145,7 +145,7 @@ class TestCaseFunction(Function):
_testcase = None # type: Optional[unittest.TestCase]
def setup(self) -> None:
- # a bound method to be called during teardown() if set (see 'runtest()')
+ # A bound method to be called during teardown() if set (see 'runtest()').
self._explicit_tearDown = None # type: Optional[Callable[[], None]]
assert self.parent is not None
self._testcase = self.parent.obj(self.name) # type: ignore[attr-defined]
@@ -164,12 +164,12 @@ class TestCaseFunction(Function):
pass
def _addexcinfo(self, rawexcinfo: "_SysExcInfoType") -> None:
- # unwrap potential exception info (see twisted trial support below)
+ # Unwrap potential exception info (see twisted trial support below).
rawexcinfo = getattr(rawexcinfo, "_rawexcinfo", rawexcinfo)
try:
excinfo = _pytest._code.ExceptionInfo(rawexcinfo) # type: ignore[arg-type]
- # invoke the attributes to trigger storing the traceback
- # trial causes some issue there
+ # Invoke the attributes to trigger storing the traceback
+ # trial causes some issue there.
excinfo.value
excinfo.traceback
except TypeError:
@@ -242,7 +242,7 @@ class TestCaseFunction(Function):
def _expecting_failure(self, test_method) -> bool:
"""Return True if the given unittest method (or the entire class) is marked
- with @expectedFailure"""
+ with @expectedFailure."""
expecting_failure_method = getattr(
test_method, "__unittest_expecting_failure__", False
)
@@ -256,23 +256,23 @@ class TestCaseFunction(Function):
maybe_wrap_pytest_function_for_tracing(self)
- # let the unittest framework handle async functions
+ # Let the unittest framework handle async functions.
if is_async_function(self.obj):
# Type ignored because self acts as the TestResult, but is not actually one.
self._testcase(result=self) # type: ignore[arg-type]
else:
- # when --pdb is given, we want to postpone calling tearDown() otherwise
+ # When --pdb is given, we want to postpone calling tearDown() otherwise
# when entering the pdb prompt, tearDown() would have probably cleaned up
- # instance variables, which makes it difficult to debug
- # arguably we could always postpone tearDown(), but this changes the moment where the
+ # instance variables, which makes it difficult to debug.
+ # Arguably we could always postpone tearDown(), but this changes the moment where the
# TestCase instance interacts with the results object, so better to only do it
- # when absolutely needed
+ # when absolutely needed.
if self.config.getoption("usepdb") and not _is_skipped(self.obj):
self._explicit_tearDown = self._testcase.tearDown
setattr(self._testcase, "tearDown", lambda *args: None)
- # we need to update the actual bound method with self.obj, because
- # wrap_pytest_function_for_tracing replaces self.obj by a wrapper
+ # We need to update the actual bound method with self.obj, because
+ # wrap_pytest_function_for_tracing replaces self.obj by a wrapper.
setattr(self._testcase, self.name, self.obj)
try:
self._testcase(result=self) # type: ignore[arg-type]
@@ -305,14 +305,14 @@ 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
+ # Let's substitute the excinfo with a pytest.skip one.
call2 = CallInfo[None].from_call(
lambda: pytest.skip(str(excinfo.value)), call.when
)
call.excinfo = call2.excinfo
-# twisted trial support
+# Twisted trial support.
@hookimpl(hookwrapper=True)
@@ -356,5 +356,5 @@ def check_testcase_implements_trial_reporter(done: List[int] = []) -> None:
def _is_skipped(obj) -> bool:
- """Return True if the given object has been marked with @unittest.skip"""
+ """Return True if the given object has been marked with @unittest.skip."""
return bool(getattr(obj, "__unittest_skip__", False))