From d74c8d52659d7db2f72f2dcbcf9a3bc97c2a6126 Mon Sep 17 00:00:00 2001 From: glacials Date: Fri, 6 Aug 2021 14:17:26 -0700 Subject: [PATCH] Fix an incompatibility with pyarmor --- coverage/context.py | 2 +- tests/test_context.py | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/coverage/context.py b/coverage/context.py index ea13da21e..90340e15b 100644 --- a/coverage/context.py +++ b/coverage/context.py @@ -48,7 +48,7 @@ def qualname_from_frame(frame): fname = co.co_name method = None if co.co_argcount and co.co_varnames[0] == "self": - self = frame.f_locals["self"] + self = frame.f_locals.get("self", None) method = getattr(self, fname, None) if method is None: diff --git a/tests/test_context.py b/tests/test_context.py index 3f80803bd..de972819f 100644 --- a/tests/test_context.py +++ b/tests/test_context.py @@ -5,6 +5,7 @@ import inspect import os.path +from unittest import mock import coverage from coverage.context import qualname_from_frame @@ -275,3 +276,8 @@ def test_bug_829(self): # A class with a name like a function shouldn't confuse qualname_from_frame. class test_something: # pylint: disable=unused-variable assert get_qualname() is None + + def test_bug_1210(self): + co = mock.Mock(co_name="a_co_name", co_argcount=1, co_varnames=["self"]) + frame = mock.Mock(f_code = co, f_locals={}) + assert qualname_from_frame(frame) == "unittest.mock.a_co_name"