Hello,
On Tue, 16 Jul 2013 11:53:17 +0200 Milo Casagrande milo.casagrande@linaro.org wrote:
Hello everyone,
one of the discussion we had during connect was to find (and use) a common testing framework for unit (and maybe beyond) tests. What we should use is probably a framework that still supports all the unittest based tests we already have in our projects.
Following also other people suggestions, I looked around and did some initial tests. What follows is a list of what we could use:
+10
Nose is truly Pythonic tool, intended to do testing pleasant and unobtrusive (while all the usual feature supported). There's no obscure APIs to learn, everything just intuitive and natural:
def test_obvious(): assert 2 + 2 == 4
def test_exc(): try: 1/0 assert False, "Math doomed" exception: pass
To run tests, just run "nosetests" - it will collected all the test from intuitive, convention-over-configuration places.
*Lot* of (truly Pythonic) projects use nosetest.
- pytest: http://pytest.org/latest/
Didn't use that, http://pytest.org/latest/getting-started.html#getstarted shows ability to write test with asserts, that's good, but then, there's nosetest already ;-).
- stick with Python provided unittest: no need to install anything
else
But very verbose, alien to Python, RSI-provoking syntax. Also, no decent test runner anyway, so something needs to be installed. nosetest can handle unittest of course.
Personally I do not dislike unittest even if of the three is the most verbose, but pytest is a powerful handy tool and easier to use (you don't even need to inherit from TestCase).
I didn't play with pytest and Django tests, but looks like it is possible to easily integrate it:
http://pytest-django.readthedocs.org/en/latest/
Tools:
These kind of tools are more targeted at mocking/patching objects or behavior, should we avoid them or use them? (no flame wars please! :-) Personally I find that sometimes (probably too often) I need them.
Sure, you can't do complete testing without them (mock objects), and without patching, can't do that comfortable (inversion of control/dependency injection is not the natural Python patterns after all).
If we need them we should suggest which one to use, and stick with it:
Classy tool, has its corner cases, but that's because it's rather powerful. Just as with nosetest, truly Python - start is easy, learn more as you need.
There are more, but these two are the ones I know about or have been using. Other suggestions?
Ciao!