My goal is to find out whether a function from one object was called before another function of another object.
class A:
def foo( self ):
...
def foo2( self ):
...
class B:
def goo( self ):
...
class C:
def func( self, a: A, b: B ):
a.foo()
a.foo2()
b.goo()
With my unit test, I would like to find out whether a.foo() was called before b.goo().
I already tried it like in the following code, but obviously, it did not work because there was the call off a.foo2() in between.
class SomeTests( unittest.TestCase ):
def test_callOrder( self ):
aMock = Mock()
bMock = Mock()
topMock = Mock()
topMock.attach_mock( aMock, 'a' )
topMock.attach_mock( bMock, 'b' )
c = C()
c.func( aMock, bMock )
expectedCalls = []
expectedCalls.append( call.a.foo() )
expectedCalls.append( call.b.goo() )
topMock.assert_has_calls( expectedCalls, any_order=False )
How can I ignore the call of a.foo2() and just focus assertion on a.foo() and b.goo()?