1

Is it possible to patch an instance attribute of a class with only a path string and not directly by importing the class and using mock.patch.object

Example:

file.py

class A:
    def __init__(self):
        self.a = 1

test_file.py

instead of

import mock
from file import A

@mock.patch.object(A, 'a', 2)
def test_a(self):
    print(A.a)

something like

import mock

@mock.patch("config.A.a", return_value=2)
def test_a(self):
    print(A.a)

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.