I am currently writing some test cases in python. I often end up calling the same two or three lines of code at the start of a test case in order to get the program I am testing going. For example:
test_something_foo(): call_method_a(x) call_method_b(y) # test some stuff test_something_bar(): call_method_a(x) call_method_b(y) # test some other stuff This means I am repeating those two lines together over and over. So I thought to extract like so:
test_something_foo(): call_method_a_and_b(x,y) # test some stuff test_something_bar(): call_method_a_and_b(x,y) # test some other stuff call_method_a_and_b(x, y): call_method_a() call_method_b() But I am not sure if this is a good idea. On the one hand it solves the "don't repeat yourself" principle, but doesn't my method "call_method_a_and_b()" violate the principle of "a method should do one thing, and one thing only". How do you reconcile those two seemingly conflicting design principles??