Should functions take extra arguments for the sake of testing?
<p>I am writing tests for a program I intend to write that checks for certain lines in configuration files.</p>

<p>For example, the program might check that the line: AllowConnections- 
is contained in the file SomeFile.conf.</p>

<p>My function stub does not take any arguments because I know the file that I am going to be checking.</p>

<p>I am trying to write a tests for this function that check the behavior for different SomeFile.conf files, but I don't see how I could do this. It is possible to change SomeFile.conf in the setup and teardown test functions, but this seems like a bad way to test. Should I change the function so that it can accept a file argument just for the sake of testing?</p>

<p>It would be quite possible to define the function as</p>

<pre><code>def checkline_in_file(filename="SomeFile.conf"):
</code></pre>

<p>Using a default value for the filename. In testing it can be overridden. In production you don't need to give it an argument.</p>

<p>Later on, when phb decides that all file extensions must have exactly 3 characters, it is a one character change.</p>

python testing