Skip to content

Commit

Permalink
Fix an incompatibility with pyarmor
Browse files Browse the repository at this point in the history
  • Loading branch information
glacials authored and nedbat committed Oct 6, 2021
1 parent 613446c commit 19545b7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion coverage/context.py
Expand Up @@ -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:
Expand Down
6 changes: 6 additions & 0 deletions tests/test_context.py
Expand Up @@ -5,6 +5,7 @@

import inspect
import os.path
from unittest import mock

import coverage
from coverage.context import qualname_from_frame
Expand Down Expand Up @@ -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"

0 comments on commit 19545b7

Please sign in to comment.