summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Finney <ben+python@benfinney.id.au>2010-01-30 16:50:32 +1100
committerBen Finney <ben+python@benfinney.id.au>2010-01-30 16:50:32 +1100
commitfac7658cfb13f42abfbb5428043a9b9d94593cd4 (patch)
treeb68d5fbe04f3c46a287f5c665a9caad2a747722a
parent87b26c7a419888489f17f26466b6176c9ad2ee90 (diff)
downloadtestscenarios-fac7658cfb13f42abfbb5428043a9b9d94593cd4.tar.gz
Append scenario name to test case short description.
-rw-r--r--lib/testscenarios/scenarios.py7
-rw-r--r--lib/testscenarios/tests/test_scenarios.py20
2 files changed, 26 insertions, 1 deletions
diff --git a/lib/testscenarios/scenarios.py b/lib/testscenarios/scenarios.py
index eacd9d2..540285a 100644
--- a/lib/testscenarios/scenarios.py
+++ b/lib/testscenarios/scenarios.py
@@ -38,8 +38,13 @@ def apply_scenario((name, parameters), test):
:param test: The test to apply the scenario to. This test is unaltered.
:return: A new test cloned from test, with the scenario applied.
"""
+ scenario_suffix = '(' + name + ')'
newtest = clone_test_with_new_id(test,
- test.id() + '(' + name + ')')
+ test.id() + scenario_suffix)
+ test_desc = test.shortDescription()
+ if test_desc is not None:
+ newtest_desc = "%(test_desc)s %(scenario_suffix)s" % vars()
+ newtest.shortDescription = (lambda: newtest_desc)
for key, value in parameters.iteritems():
setattr(newtest, key, value)
return newtest
diff --git a/lib/testscenarios/tests/test_scenarios.py b/lib/testscenarios/tests/test_scenarios.py
index 63a5992..087d987 100644
--- a/lib/testscenarios/tests/test_scenarios.py
+++ b/lib/testscenarios/tests/test_scenarios.py
@@ -117,6 +117,17 @@ class TestApplyScenario(testtools.TestCase):
class ReferenceTest(unittest.TestCase):
def test_pass(self):
pass
+ def test_pass_with_docstring(self):
+ """ The test that always passes.
+
+ This test case has a PEP 257 conformant docstring,
+ with its first line being a brief synopsis and the
+ rest of the docstring explaining that this test
+ does nothing but pass unconditionally.
+
+ """
+ pass
+
self.ReferenceTest = ReferenceTest
def test_sets_specified_id(self):
@@ -132,6 +143,15 @@ class TestApplyScenario(testtools.TestCase):
modified_test = apply_scenario(self.scenario, raw_test)
self.assertEqual('bar', modified_test.foo)
+ def test_appends_scenario_name_to_short_description(self):
+ raw_test = self.ReferenceTest('test_pass_with_docstring')
+ modified_test = apply_scenario(self.scenario, raw_test)
+ raw_doc = self.ReferenceTest.test_pass_with_docstring.__doc__
+ raw_desc = raw_doc.split("\n")[0].strip()
+ scenario_name = self.scenario_name
+ expect_desc = "%(raw_desc)s (%(scenario_name)s)" % vars()
+ self.assertEqual(expect_desc, modified_test.shortDescription())
+
class TestApplyScenarios(testtools.TestCase):
def test_calls_apply_scenario(self):