diff options
author | Stephan Richter <stephan.richter@gmail.com> | 2019-05-12 12:17:41 -0400 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2019-06-10 17:15:32 -0400 |
commit | c399478e86892f0e7ade51873dfbe13f87ecfa83 (patch) | |
tree | fb57f3945c364c35be7ffcb1fedfa1314be58104 | |
parent | e1574b260db45ec00074c1d9aafc3586cb3952a0 (diff) | |
download | python-coveragepy-git-c399478e86892f0e7ade51873dfbe13f87ecfa83.tar.gz |
Support for full qnames for old-style classes.
-rw-r--r-- | coverage/context.py | 16 | ||||
-rw-r--r-- | tests/test_context.py | 2 |
2 files changed, 16 insertions, 2 deletions
diff --git a/coverage/context.py b/coverage/context.py index fb1b76ac..d2f75db2 100644 --- a/coverage/context.py +++ b/coverage/context.py @@ -78,5 +78,19 @@ def qualname_from_frame(frame): qname = cls.__module__ + '.' + cls.__name__ + "." + fname break else: - qname = func.__module__ + '.' + fname + # Support for old-style classes. + def mro(bases): + for base in bases: + f = base.__dict__.get(fname, None) + if f is func: + return base.__module__ + '.' + base.__name__ + "." + fname + for base in bases: + qname = mro(base.__bases__) + if qname is not None: + return qname + return None + qname = mro([self.__class__]) + if qname is None: + qname = func.__module__ + '.' + fname + return qname diff --git a/tests/test_context.py b/tests/test_context.py index 0aa31e4b..0baa51e9 100644 --- a/tests/test_context.py +++ b/tests/test_context.py @@ -284,4 +284,4 @@ class QualnameTest(CoverageTest): if not env.PY2: self.skipTest("Old-style classes are only in Python 2") self.assertEqual(OldStyle().meth(), "tests.test_context.OldStyle.meth") - self.assertEqual(OldChild().meth(), "tests.test_context.OldChild.meth") + self.assertEqual(OldChild().meth(), "tests.test_context.OldStyle.meth") |