Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix an incompatibility with pyarmor #1210

Merged
merged 1 commit into from Oct 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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"