Skip to content

Commit 19545b7

Browse files
glacialsnedbat
authored andcommittedOct 6, 2021
Fix an incompatibility with pyarmor
1 parent 613446c commit 19545b7

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed
 

‎coverage/context.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def qualname_from_frame(frame):
4848
fname = co.co_name
4949
method = None
5050
if co.co_argcount and co.co_varnames[0] == "self":
51-
self = frame.f_locals["self"]
51+
self = frame.f_locals.get("self", None)
5252
method = getattr(self, fname, None)
5353

5454
if method is None:

‎tests/test_context.py

+6
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import inspect
77
import os.path
8+
from unittest import mock
89

910
import coverage
1011
from coverage.context import qualname_from_frame
@@ -275,3 +276,8 @@ def test_bug_829(self):
275276
# A class with a name like a function shouldn't confuse qualname_from_frame.
276277
class test_something: # pylint: disable=unused-variable
277278
assert get_qualname() is None
279+
280+
def test_bug_1210(self):
281+
co = mock.Mock(co_name="a_co_name", co_argcount=1, co_varnames=["self"])
282+
frame = mock.Mock(f_code = co, f_locals={})
283+
assert qualname_from_frame(frame) == "unittest.mock.a_co_name"

0 commit comments

Comments
 (0)
Please sign in to comment.