title: Making a Python unit test that never runs in parallel
body: <p><strong>tl;dr -</strong> I want to write a Python <code>unittest</code> function that deletes a file, runs a test, and the restores the file. This causes race conditions because <code>unittest</code> runs multiple tests in parallel, and deleting and creating the file for one test messes up other tests that happen at the same time.</p>
  
  <p><strong>Long Specific Example:</strong></p>
  
  <p>I have a Python module named <code>converter.py</code> and it has associated tests in <code>test_converter.py</code>. If there is a file named <code>config_custom.csv</code> in the same directory as <code>converter.py</code>, then the custom configuration will be used. If there is no custom CSV config file, then there is a default configuration built into <code>converter.py</code>.</p>
  
  <p>I wrote a unit test using <code>unittest</code> from the Python 2.7 standard library to validate this behavior. The unit test in <code>setUp()</code> would rename <code>config_custom.csv</code> to <code>wrong_name.csv</code>, then it would run the tests (hopefully using the default config), then in <code>tearDown()</code> it would rename the file back the way it should be.</p>
  
  <p><strong>Problem:</strong> Python unit tests run in parallel, and I got terrible race conditions. The file <code>config_custom.csv</code> would get renamed in the middle of other unit tests in a non-deterministic way. It would cause at least one error or failure about 90% of the time that I ran the entire test suite.</p>
  
  <p>The ideal solution would be to tell <code>unittest</code>: <strong>Do NOT</strong> run this test in parallel with other tests, this test is special and needs complete isolation.</p>
  
  <p>My work-around is to add an optional argument to the function that searches for config files. The argument is only passed by the test suite. It ignores the config file without deleting it. Actually deleting the test file is more graceful, that is what I actually want to test.</p>