Short Question
What is the best way to get data into a Python unittest case ?
Background
My project is using Python's unittest module as an automated way execute a series of tests that will need to run on many of the same type of boards. So far this is a good fit to what the unittest module was designed for; the twist is that each test case needs to know run specific information to store in a Django database.
The data that needs to be passed in includes a serial number, who tested the board, the date, and other things of this nature. It is worth noting that the order in which the boards will be tested is chosen by a human that pulls board X from a box, so predicting the serial number is not possible.
Thoughts
Currently, I am passing the required data to and from the test cases via pickle. This method works fine in small testing, but my concern is reading and writing to the same file 100k + times gives lots of room for data corruption (+ it's not that fast). I wrote an answer to a SO Question that redirects the stdin in a way that I think might work well for this application as well.
The next step is going to be wrap a GUI around these tests. A personal goal would be to have the ability to run the tests via command line then have the GUI call the same command line functions. For this reason I am leaning towards moving to the redirected stdin.
System / Deployment Information
Required OS Support: Windows XP and Windows 7
Ideal OS Support: Mac OS X and Linux
Python Version: 2.7
Any thoughts or comments would be greatly appreciated.
I have created unittests which test against a third party service (Zoho CRM). To test the service API, you need to store username and password crendetials.
Since this is premium service and you are creating open source software, naturally you cannot hardcode your login credentials to the source code itself.
So I ended up using environment variables - work quite well:
Here is the example:
https://github.com/miohtama/mfabrik.zoho/blob/master/mfabrik/zoho/tests.py
As a bigger problem I think trying to enforce unit tests module to do something it was not supposed to do in the first place is not a good idea. Maybe you should try to write your own unit test runner which would do necessary preparements (pulling info, storing results) somewhere.