Test Driven Development in Python
oreillynet.com
oreillynet.com
i like to write tests before my code when i am trying to solve a specific problem, or think of a new potential issue and want to test it, but i find "pure" TDD takes it way too far. i don't see practical use in exhaustively testing every single potential case for a simple wrapper around datetime. i do like the idea for really critical sections, but it seems way overkill for most code.
TDD to me seems, like most things, as a good tool to have in the tool box, but moderation is key. articles like this are helpful to describe the practice but tend to always prescribe it for everything.
And in general, avionics software development does feel both very inefficient and (mostly) very simple. But our customers are very happy when it doesn't crash (figuratively or literally)!
Like most things in life, it's about moderation. Do you need 80+% test coverage on your "tweet this" feature? No. Do you need 90+% test coverage of your signup and ecommerce process flows? Absolutely!
Don't get hung up writing trivial tests as you described above, instead focus on the things that really matter.
Is there something similar in setup.py? If so, how does it find which files have tests to run?
edit: So there really isn't a standard Python way to 'run all unit tests?' (I'm not counting v2.7 because Python unit tests have been around a lot longer than that version has). I thought that Python was all about "there's only one way to do it." I find it a little odd that it took so long for anything like that to be included in the main distribution.
python -m unittest discover
The docs are here:
http://docs.python.org/library/unittest.html#test-discovery
I've actually been using both unittest and pytest for a while - I like pytest better but they are both nice tools.
http://doc.pytest.org/en/latest/
I found Tarek Ziade's book useful when learning how to best set up and execute unit tests as part of my python projects.
nose will adjust sys.path to make sure your tests can find the packages they're testing. This may depend a bit on the layout you're using for your project, it has always worked for me so I have never had the need to look into HOW it works :)
In such example, the benefit would be that a change in the date matching algorithm could be done later and rely on the unit tests to detect a regression.