summaryrefslogtreecommitdiff
path: root/src/_pytest/unittest.py
diff options
context:
space:
mode:
authorRan Benita <ran@unusedvar.com>2020-02-21 17:03:46 +0200
committerRan Benita <ran@unusedvar.com>2020-02-28 14:34:44 +0200
commitd636fcd557c543f31859eb8ead4bc4740ac5d5cd (patch)
tree1fff9a122ff171ce6945ea393a3c79245aafc723 /src/_pytest/unittest.py
parentf77d606d4eeba38352bd3ea960f44b171fe06c1f (diff)
downloadpytest-d636fcd557c543f31859eb8ead4bc4740ac5d5cd.tar.gz
Add a typing-compatible mechanism for ad-hoc attributes on various objects
pytest has several instances where plugins set their own attributes on objects they receive in hooks, like nodes and config. Since plugins are detached from these object's definition by design, this causes a problem for type checking because these attributes are not defined and mypy complains. Fix this by giving these objects a "store" which can be used by plugins in a type-safe manner. Currently this mechanism is private. We can consider exposing it at a later point.
Diffstat (limited to 'src/_pytest/unittest.py')
-rw-r--r--src/_pytest/unittest.py6
1 files changed, 4 insertions, 2 deletions
diff --git a/src/_pytest/unittest.py b/src/_pytest/unittest.py
index a5512e944..2047876e5 100644
--- a/src/_pytest/unittest.py
+++ b/src/_pytest/unittest.py
@@ -14,6 +14,8 @@ from _pytest.outcomes import xfail
from _pytest.python import Class
from _pytest.python import Function
from _pytest.runner import CallInfo
+from _pytest.skipping import skipped_by_mark_key
+from _pytest.skipping import unexpectedsuccess_key
def pytest_pycollect_makeitem(collector, name, obj):
@@ -174,7 +176,7 @@ class TestCaseFunction(Function):
try:
skip(reason)
except skip.Exception:
- self._skipped_by_mark = True
+ self._store[skipped_by_mark_key] = True
self._addexcinfo(sys.exc_info())
def addExpectedFailure(self, testcase, rawexcinfo, reason=""):
@@ -184,7 +186,7 @@ class TestCaseFunction(Function):
self._addexcinfo(sys.exc_info())
def addUnexpectedSuccess(self, testcase, reason=""):
- self._unexpectedsuccess = reason
+ self._store[unexpectedsuccess_key] = reason
def addSuccess(self, testcase):
pass