title: Mocking a class attribute
body: <p>I have a class with a single class attribute that I want to mock</p>
  <p>my_class.py</p>
  <pre><code>class MyClass:
  
      __attribute = ['123', '456']
  </code></pre>
  <p>test_my_class.py</p>
  <pre><code>import pytest
  from directory.my_class import MyClass
  
  def test_1(mocker):
      with mocker.patch.object(MyClass, '__attribute', {'something': 'new'}):
          test = MyClass()
  </code></pre>
  <p>I get:</p>
  <pre><code>E           AttributeError: &lt;class 'directory.my_class.MyClass'&gt; does not have the attribute '__attribute'
  </code></pre>
  <p>I also get the same error when trying:</p>
  <pre><code>def test_2(mocker):
      with mocker.patch('directory.my_class.MyClass.__attribute', new_callable=mocker.PropertyMock) as a:
          a.return_value = {'something': 'new'}
          test = MyClass()
  </code></pre>
  <p>I've also tried a direct assignment along with the other suggestions in this post:
  <a href="https://stackoverflow.com/questions/22324628/better-way-to-mock-class-attribute-in-python-unit-test">Better way to mock class attribute in python unit test</a></p>
  <p>My project is using a mocker fixture from this plugin: <a href="https://pypi.org/project/pytest-mock/" rel="nofollow noreferrer">https://pypi.org/project/pytest-mock/</a></p>