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>The code you test, and the code you run should be same.</p>

<p>I do not recommend using a filename, because now you are dealing with (in one function) opening the file - and the errors associated with that part, and then confirming the file format (the actual purpose of the function).</p>

<p>It sounds to me that your function's job is to check if the file's contents contain a specific string. So, this function should take any type of content element (an iterable) and then as long as the key string is not found, the function should return None/False/Fail condition - and your test should check for that.</p>

python testing