Deal with leading whitespace in docstrings
diff --git a/nose_parameterized/parameterized.py b/nose_parameterized/parameterized.py
index 277ffa2..a82805e 100644
--- a/nose_parameterized/parameterized.py
+++ b/nose_parameterized/parameterized.py
@@ -194,7 +194,7 @@
# The documentation might be a multiline string, so split it
# and just work with the first string, ignoring the period
# at the end if there is one.
- first, nl, rest = func.__doc__.partition("\n")
+ first, nl, rest = func.__doc__.lstrip().partition("\n")
suffix = ""
if first.endswith("."):
suffix = "."
diff --git a/nose_parameterized/test.py b/nose_parameterized/test.py
index 40150f1..3a6f3e7 100644
--- a/nose_parameterized/test.py
+++ b/nose_parameterized/test.py
@@ -122,7 +122,7 @@
class TestParameterizedExpandDocstring(TestCase):
- def _assert_docstring(self, expected_docstring):
+ def _assert_docstring(self, expected_docstring, rstrip=False):
""" Checks the current test method's docstring. Must be called directly
from the test method. """
stack = inspect.stack()
@@ -133,7 +133,10 @@
)
if test_method is None:
raise AssertionError("uh oh, unittest changed a local variable name")
- assert_equal(test_method.__doc__, expected_docstring)
+ actual_docstring = test_method.__doc__
+ if rstrip:
+ actual_docstring = actual_docstring.rstrip()
+ assert_equal(actual_docstring, expected_docstring)
@parameterized.expand([param("foo")],
doc_func=lambda f, n, p: "stuff")
@@ -171,6 +174,13 @@
"""Documentation"""
self._assert_docstring("Documentation [with foo=%r, bar=%r]" %(foo, bar))
+ @parameterized.expand([param("foo", )])
+ def test_with_leading_newline(self, foo, bar=12):
+ """
+ Documentation
+ """
+ self._assert_docstring("Documentation [with foo=%r, bar=%r]" %(foo, bar), rstrip=True)
+
def test_warns_when_using_parameterized_with_TestCase():
try: