Example of using @raises to test the raising of an exception.
authorBen Waugh <b.waugh@ucl.ac.uk>
Thu, 11 Apr 2013 08:52:21 +0000 (09:52 +0100)
committerW. Trevor King <wking@tremily.us>
Fri, 1 Nov 2013 20:42:52 +0000 (13:42 -0700)
testing/cheat-sheet.md

index 140e098658cecc8add0d8aa38d179b3186d61658..d7f48a02f1c1a793fb437de7398af3438fb30bf9 100644 (file)
@@ -86,9 +86,15 @@ the way values are represented and rounded.
 
 ### Testing exceptions
 
-TODO:
+Testing that a method raises the appropriate exception when the input is invalid:
+
+    from nose.tools import raises
+
+    from mystatscode import mean
 
-* using `@raises` decorator
+    @raises(TypeError)
+    def test_not_a_list():
+        observed = mean(1)
 
 ### Fixtures