python - Mocking class instances inside a Class -
I am currently writing a test for a wsgi server built in During the tests, I How can I duplicate myself and A. And B.K. As myself.I have created them as spider orbits? I write more python More inquisitive I am about such situations My inclination is usually to present dependency injection and to pass on A and B classes built on the manufacturer. It makes it easy for both of them to see external dependencies and when they need it, they have to change, but sometimes it is redundant. Not only do you: __init __ constructor Server class governs 2 instances of other sections as members. Let's say
def __init __ (self): self.a = A () self.b = B ()
# I use it if I want to duplicate the entire server clique @ imitation 'Myproject.server.MyServerClass', autospec = true)
server = server () server.a = MockA () server.b = MockB ()
Comments
Post a Comment