How can I unit-test a method without instantiating the class?
methods, python, unit-testing
Solution
The main hacky way I can think of is making a subclass and overriding `__init__`:
class FakeSocketHandlerForTesting(SocketHandler):
def __init__(self, *args, **args):
pass
You can even set the attributes it ought to have by hand in the unit test.
Still, better to reduce the coupling, of course.
Problem
I have a class `SocketHandler` with a method `calculate_ticket`: ``` class SocketHandler(A, B, C ..): .. calculate_ticket(self, key): .. return ticket .. ``` Now I want to test the method without having to instantiate the class since it is coupled with so many things. Is this possible?