Created
October 10, 2012 04:20
-
-
Save showell/3863138 to your computer and use it in GitHub Desktop.
xunit is cruft in python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
TESTS = [] | |
def suite(): | |
for test in TESTS: | |
print 'running %s' % test.__name__ | |
test() | |
def test(f): | |
TESTS.append(f) | |
return f | |
@test | |
def basic_arithmetic(): | |
assert 1 + 1 == 2 | |
@test | |
def basic_array_stuff(): | |
assert 1 in [1, 2] | |
suite() |
Yup, of course, but Python's bare assert already gives you the line number, which gets you 99% there. And assert_equals is trivial to write. The one thing that's slightly painful to reinvent is assert_raises. The point of this gist isn't necessarily to argue against xunit; it's more to show that the fundamental pieces of xunit are dirt simple to simulate without the framework. (This would be less true in Java, I imagine.)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey showell!
Though this is mostly true, there are still some niceties that you'll have to
reproduce, one by one. Look at the badness of the output of:
Shows this:
Notice how there's nothing about
3
anywhere in there. ☹