Python Forum
Using Mock with python
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Using Mock with python
#2
You need to pass the instance in as a function parameter then. That's what dependency injection is - you take the responsibility of supplying the dependency out of the class that uses it, so that you can substitute different implementations as necessary (like here for testing).

Also, do you really need to use MagicMock? I mean, it's pretty much straightforward to define a class that has the right method and returns the value you want:

class FakeClient:
    def get_value(self, feature_eng):
        return "true"
Since Python has duck typing, you don't need to worry about inheriting from AppClient
Reply


Messages In This Thread
Using Mock with python - by Hocinema - Oct-10-2021, 12:17 AM
RE: Using Mock with python - by ndc85430 - Oct-10-2021, 12:01 PM
RE: Using Mock with python - by Hocinema - Oct-10-2021, 10:05 PM
RE: Using Mock with python - by Hocinema - Oct-11-2021, 12:33 PM
RE: Using Mock with python - by Hocinema - Oct-11-2021, 09:09 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020