Answering your first question, the correct way to mock with @patch decorator is to pass the correct target namespace as a first argument. So, instead of @patch('git.repo.base.Repo'), you should pass the class Repo with your script's namespace, so assuming your someFunction() to test is placed in someScript.py script, which is placed in someModule module and imports class Repo, the correctly patched test would look like this:
@patch('someModule.someScript.Repo')
def test_some_function(self, mock):
# test code
There is a special documentation part which touches upon this issue, I strongly recommend you to read it. You can also see a similar question and its answer.
Regarding second question, @mock.patch.object decorators work like all other Python decorators (link to question about Python decorators). When stacked, they are applied from bottom to top, so after editing your example to make it proper Python (@mock.patch.object requires two parameters):
class A:
def __init__(self):
self.a = 'a'
self.b = 'b'
self.c = 'c'
a = A()
class ATest(TestCase):
@mock.patch.object(a, 'a')
@mock.patch.object(a, 'b')
@mock.patch.object(a, 'c')
def test_something(self, mocker1, mocker2, mocker3):
# test code...
mocker1 refers to mocked attribute c, mocker2 to attribute b and mocker3 to attribute a. That's because @ decorator syntax is translated to:
test_a = mock.patch.object(a, 'a')(mock.patch.object(a, 'b')(mock.patch.object(a, 'c')(test_a)))
So you can see that c decorator is the most nested, so it's applied as the first one (even though it is defined as a last one). That's why (maybe a bit counterintuitively) decorator which is defined last is assigned to first parameter of a test function.
someFunctionis not correct Python. IfsomeFunctionworks only withRepoobject, what do you aim to test if you mock theRepoobject? BTW you should not include two questions in one.