Skip to content

monkeypatch.delattr doesn't handle classmethod or staticmethod #4536

@chdsbd

Description

@chdsbd

The following example fails

class SampleParent(object):
    @classmethod
    def hello(_cls):
        pass

class SampleChild(SampleParent):
    pass

monkeypatch = MonkeyPatch()
original = SampleChild.hello
monkeypatch.delattr(SampleParent, 'hello')
monkeypatch.undo()
assert original == SampleChild.hello

This issue was fixed for setattr via #156

We need to make a similar check in delattr as seen here:

if inspect.isclass(target):

I'll put up a PR.

Metadata

Metadata

Assignees

No one assigned

    Labels

    plugin: monkeypatchrelated to the monkeypatch builtin plugintype: bugproblem that needs to be addressed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions