1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] How to patch an attribute in an object

Discussão em 'Python' iniciado por Stack, Setembro 10, 2024.

  1. Stack

    Stack Membro Participativo

    The question is how to patch an attribute of an instance within a with statement. I tried with following example which doesn't work. It prints as in the comment.

    from mock import patch, PropertyMock

    class Foo(object):
    f = {'a': 1}

    new_foo = Foo()

    with patch.object(new_foo, 'f', new_callable=PropertyMock) as mock:
    mock.return_value = {'b': 2}
    print new_foo.f
    # <PropertyMock name='f' id='4474801232'>

    Continue reading...

Compartilhe esta Página