-2

I have a Python method in a class like below.

method_A(self):
    self.method1(self)
    self.method2(self)
    self.method3(self)

I need to call the entire methodA() in another Python class by excluding only self.method3(self) from the methodA().

Could you please help me to achieve it? I don't want to duplicate the code just to exclude one method.

  • 2
    why and what is the context for you to do this? – Dean Van Greunen Aug 30 '22 at 15:12
  • Does this answer your question? [Python: How to execute only parts of a function?](https://stackoverflow.com/questions/20926889/python-how-to-execute-only-parts-of-a-function) – mkrieger1 Aug 30 '22 at 15:12
  • 1
    If you can modify `method_A`, then this is trivial. If you can't, then I don't see how it's possible. – d.b Aug 30 '22 at 15:15
  • 1
    You could *patch* `method3` so that what gets called does nothing, but it's a pretty big hack. *Why* do you need `methodA` to do something it's not designed to do? – chepner Aug 30 '22 at 15:15
  • 1
    If you need to do only part of a function, your function is probably doing too many things. Restructure it so that the individual parts are easier to reuse. – Samwise Aug 30 '22 at 15:16
  • Thank you each and everyone for your suggestions! The main reason is - I have a method where it calls 10 methods inside it. Now, I am building another module in which I need to call this method(which has 10 methods inside it) and out of 10 , I need to use only 9 methods. Therefore, I was looking for the same. However, I have added a Boolean variable inside the calling method argument and just called this method in my module with just a boolean value so that my code need not be duplicated. My solution worked very similar to the link provided by @mkrieger1. – Ravi Teja Kothuru Sep 01 '22 at 18:47

1 Answers1

-1

You can use the @SkipTest annotation from the unittest module to exclude a specific method from being run.