summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2018-09-28 20:31:42 -0400
committerNed Batchelder <ned@nedbatchelder.com>2018-09-28 20:31:42 -0400
commitb528c1e91d56761e7ca89074164859f26bfdd7f3 (patch)
tree67be7d21f155d3a9aae7dd4afacdd4c124d5a7eb
parentf9cfc98ebf12f3f04479bee9fab9358fdf9d4559 (diff)
downloadpython-coveragepy-git-b528c1e91d56761e7ca89074164859f26bfdd7f3.tar.gz
Deal with properties in qualname_from_frame
-rw-r--r--coverage/context.py5
-rw-r--r--tests/test_context.py15
2 files changed, 18 insertions, 2 deletions
diff --git a/coverage/context.py b/coverage/context.py
index f167de36..c3416208 100644
--- a/coverage/context.py
+++ b/coverage/context.py
@@ -31,7 +31,10 @@ def qualname_from_frame(frame):
if method is None:
return fname
- func = method.__func__
+ func = getattr(method, '__func__', None)
+ if func is None:
+ return fname
+
if hasattr(func, '__qualname__'):
qname = func.__qualname__
else:
diff --git a/tests/test_context.py b/tests/test_context.py
index eeca81cd..2473c694 100644
--- a/tests/test_context.py
+++ b/tests/test_context.py
@@ -188,7 +188,12 @@ class DynamicContextWithPythonTracerTest(CoverageTest):
def get_qualname():
"""Helper to return qualname_from_frame for the caller."""
- caller_frame = inspect.stack()[1][0]
+ stack = inspect.stack()[1:]
+ if any(sinfo[0].f_code.co_name == "get_qualname" for sinfo in stack):
+ # We're calling outselves recursively, maybe because we're testing
+ # properties. Return an int to try to get back on track.
+ return 17
+ caller_frame = stack[0][0]
return qualname_from_frame(caller_frame)
@@ -196,6 +201,10 @@ class Parent(object): # pylint: disable=missing-docstr
def meth(self):
return get_qualname()
+ @property
+ def a_property(self):
+ return get_qualname()
+
class Child(Parent): # pylint: disable=missing-docstring
pass
@@ -225,3 +234,7 @@ class QualnameTest(CoverageTest):
def test_fake_out(self):
self.assertEqual(fake_out(0), "fake_out")
+
+ def test_property(self):
+ # I'd like this to be "Parent.a_property", but this might be ok too.
+ self.assertEqual(Parent().a_property, "a_property")