Skip to content

Commit b8e1e8c

Browse files
committed
wip: as suggested in the issue, but breaks a test
1 parent f85d9b7 commit b8e1e8c

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

coverage/context.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,10 @@ def qualname_from_frame(frame: FrameType) -> str | None:
6464
if method is None:
6565
func = frame.f_globals.get(fname)
6666
if func is None:
67-
return None
67+
try:
68+
return frame.f_code.co_qualname
69+
except AttributeError:
70+
return f"staticmethod({fname})"
6871
return cast(str, func.__module__ + "." + fname)
6972

7073
func = getattr(method, "__func__", None)

tests/test_context.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,14 @@ def meth(self) -> str | None:
230230
def a_property(self) -> str | None:
231231
return get_qualname()
232232

233+
@staticmethod
234+
def statmeth() -> str | None:
235+
return get_qualname()
236+
237+
@classmethod
238+
def classmeth(cls) -> str | None:
239+
return get_qualname()
240+
233241
class Child(Parent):
234242
pass
235243

@@ -283,6 +291,12 @@ def test_fake_out(self) -> None:
283291
def test_property(self) -> None:
284292
assert Parent().a_property == "tests.test_context.Parent.a_property"
285293

294+
def test_staticmethod(self) -> None:
295+
assert Parent().statmeth() == "xyzzy"
296+
297+
def test_classmethod(self) -> None:
298+
assert Parent().classmeth() == "xyzzy"
299+
286300
def test_changeling(self) -> None:
287301
c = Child()
288302
c.meth = patch_meth # type: ignore[assignment]

0 commit comments

Comments
 (0)