python - Mocking class instances inside a Class -


I am currently writing a test for a wsgi server built in __init __ constructor Server class governs 2 instances of other sections as members. Let's say

  def __init __ (self): self.a = A () self.b = B ()   

During the tests, I How can I duplicate myself and A. And B.K. As myself.I have created them as spider orbits?

  # I use it if I want to duplicate the entire server clique @ imitation 'Myproject.server.MyServerClass', autospec = true)    

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:

  server = server () server.a = MockA () server.b = MockB ()    

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -