Tuesday, April 08, 2008

Unit testing and doc testing are working in the Django-based project. A couple wrinkles:

1. In the unit tests, I created some model instances in the setUp() method easily. I then discovered that the setUp() method is called before every method in the test class, not just once when the test class is instantiated. Ah yes, I remember this from Java days too. Is there some deep reason why tests (in this case functional tests) shouldn't share the exact same setup but need to recreate it? The fix that seemed to meld most smoothly with what the unit testing framework offered, was to tearDown() all the model instances after every test method, even if I was going to use the same work for the next test.

2. Django only seems to pick up doctests in the models module. I found a hint online (can't even find it anymore) about creating a "__test__" dictionary and putting this in models.py worked:
__test__ =  {"1": Source, "2": DataFrame}

In this case Source is a class in models.py, and DataFrame is a class imported from a file called query.py. The labels "1" and "2" are arbitrary and I don't yet know how they're used. What worries me about this is that I don't want to import everything into the models module in order to test it.

No comments:

Blog Archive

Creative Commons License
This work is licensed under a Creative Commons Attribution 3.0 Unported License.