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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

spy on frozen dataclass #280

Open
jennydaman opened this issue Feb 11, 2022 · 1 comment
Open

spy on frozen dataclass #280

jennydaman opened this issue Feb 11, 2022 · 1 comment

Comments

@jennydaman
Copy link

jennydaman commented Feb 11, 2022

Spy does not work on frozen dataclasses, it would be nice if it did (for instance, by using object.__setattr__(obj, name, spy)

from dataclasses import dataclass
from typing import Callable


def noop(*args, **kwargs):
    pass


@dataclass(frozen=True)
class MyFrozenClass:
    something: Callable = noop


def test_spy_frozen_dataclass(mocker: MockerFixture):
    o = MyFrozenClass()
    spy = mocker.spy(o, 'something')

Anyone also in this situation can use this workaround:

def test_spy_frozen_dataclass(mocker: MockerFixture):
    o = MyFrozenClass()
    spy = mocker.MagicMock(wraps=o.something)
    object.__setattr__(o, 'something', spy)
@nicoddemus
Copy link
Member

Hi @jennydaman,

Thanks for the suggestion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants