From f27b415c8366137250353dab62e549e45d07d14f Mon Sep 17 00:00:00 2001 From: Scott Sanderson Date: Thu, 21 Jan 2016 21:09:20 -0500 Subject: [PATCH] DOC: Docs updates for subtest and parameter_space. --- zipline/utils/test_utils.py | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/zipline/utils/test_utils.py b/zipline/utils/test_utils.py index 3f9a5895..ad88c4fc 100644 --- a/zipline/utils/test_utils.py +++ b/zipline/utils/test_utils.py @@ -567,13 +567,18 @@ class SubTestFailures(AssertionError): def subtest(iterator, *_names): - """Construct a subtest in a unittest. + """ + Construct a subtest in a unittest. - This works by decorating a function as a subtest. The test will be run - by iterating over the ``iterator`` and *unpacking the values into the - function. If any of the runs fail, the result will be put into a set and - the rest of the tests will be run. Finally, if any failed, all of the - results will be dumped as one failure. + Consider using ``zipline.utils.test_utils.parameter_space`` when subtests + are constructed over a single input or over the cross-product of multiple + inputs. + + ``subtest`` works by decorating a function as a subtest. The decorated + function will be run by iterating over the ``iterator`` and *unpacking the + values into the function. If any of the runs fail, the result will be put + into a set and the rest of the tests will be run. Finally, if any failed, + all of the results will be dumped as one failure. Parameters ---------- @@ -615,6 +620,10 @@ def subtest(iterator, *_names): We cannot use ``unittest2.TestCase.subTest`` because nose, pytest, and nose2 do not support ``addSubTest``. + + See Also + -------- + zipline.utils.test_utils.parameter_space """ def dec(f): @wraps(f) @@ -735,11 +744,16 @@ def parameter_space(**params): Usage ----- + >>> from unittest import TestCase >>> class SomeTestCase(TestCase): ... @parameter_space(x=[1, 2], y=[2, 3]) ... def test_some_func(self, x, y): ... # Will be called with every possible combination of x and y. ... self.assertEqual(somefunc(x, y), expected_result(x, y)) + + See Also + -------- + zipline.utils.test_utils.subtest """ def decorator(f):