From bb75b7999d65a69a0d806e6ae56e3bb7e2d83b36 Mon Sep 17 00:00:00 2001 From: Niranjan M.R Date: Mar 21 2018 14:51:45 +0000 Subject: Add support for Test case title specified in multiple lines. Add comments for better clarity with regard to catching. exception when there are no spaces after the Title section Also check for cases where the are no spaces between different sections like (Title,id etc). fixes issue #5 Signed-off-by: Niranjan M.R --- diff --git a/pytest_modifyjunit/plugin.py b/pytest_modifyjunit/plugin.py index 985f380..d3f74d1 100644 --- a/pytest_modifyjunit/plugin.py +++ b/pytest_modifyjunit/plugin.py @@ -41,7 +41,7 @@ class ModifyJunit(object): reporter = self.junit.node_reporter(report.nodeid) reporter.add_property(name, value) else: - pass #plugin is installed but not run with --junitxml + pass # plugin is installed but not run with --junitxml def _add_marks(self, item, report): """ add markers to the junit xml """ @@ -61,11 +61,34 @@ class ModifyJunit(object): rep = outcome.get_result() title_regex = re.compile("^.[T|t]itle\s*:\s*.*") if item._obj.__doc__: - tc_name = item._obj.__doc__.strip().split('\n')[0] - for line in item._obj.__doc__.strip().split('\n'): + doc_strings = item._obj.__doc__.strip() + doc_list = re.sub('(\n\s*[:|@][A-Za-z0-9_-]*:)', '\n\\1', + doc_strings, 0, re.DOTALL).split('\n') + tc_name = doc_list[0] + # Get index of test case title + for line in doc_list: if title_regex.match(line): - tc_name = re.sub("^.[T|t]itle\s*:\s*", "", line) - break + tc_start = doc_list.index(line) + # get the end of title which is a space + if len(doc_strings) > 1: + try: + # when having multiple paragraphs in docstrings + # splitting with new line causes line breaks + # represented with spaces. + # so end of the Title string is till the + # next space in the list. + tc_end = doc_list.index('', (tc_start)) + except ValueError: + # in the case where docstrings contain single line + # or single paragraph with only @Title. + # there will be no space so ValueError + # exception is caught.in which case + # length of title is till end of the docstrings. + tc_end = len(doc_list) + tc_title = ' '.join([tc.strip() for tc in doc_list[tc_start: tc_end]]) + else: + tc_title = ''.join(doc_list[tc_start]) + tc_name = re.sub("^.[T|t]itle\s*:\s*", "", tc_title) rep.nodeid = '::'.join(rep.nodeid.split('::')[0:-1]) + \ '::' + tc_name if 'call' in rep.when: diff --git a/setup.py b/setup.py index edbb349..d09b834 100644 --- a/setup.py +++ b/setup.py @@ -8,7 +8,7 @@ with io.open('README.rst', 'rt', encoding='utf-8') as f: setup_args = dict( name = "pytest-modifyjunit", - version = "1.1", + version = "1.2", description = "Utility for adding additional properties to junit xml for IDM QE", long_description = readme_contents, license = "GPL", diff --git a/test/a.xml b/test/a.xml index 9a8e387..dd33ba1 100644 --- a/test/a.xml +++ b/test/a.xml @@ -1 +1 @@ - + \ No newline at end of file diff --git a/test/test_0001.py b/test/test_0001.py index d082b4c..bfccf2e 100644 --- a/test/test_0001.py +++ b/test/test_0001.py @@ -60,3 +60,70 @@ class TestClass1(object): :title : IDM-IPA-TC: test suite: test case 0009 """ pass + + def test_000010(self): + """ + @Title: IDM-SSSD-TC: test provider: test_suite + This is a long test case name example containing + more than 80 characters + """ + pass + + def test_000011(self): + """ + + :title: IDM-SSSD-TC: test suite: test case 000011 + This is a very very long test case name containing more than + 120 characters in the test case title + """ + pass + + + def test_000012(self): + """ + :title: IDM-SSSD-TC: test suite: test case 000012 + This is a very very very very long test case name containing more than + 120 characters in the test case title + + @Description: This is a test case description + """ + + def test_000013(self): + """ + @Title: IDM-SSSD-TC: test provider: test_suite + @Id: Testcase ID:0000 + """ + pass + + def test_000014(self): + """ + :title : IDM-IPA-TC: test suite: test case 00014 + :description: Test case descrption + """ + pass + + def test_000015(self): + """ + @Title: IDM-SSSD-TC: test provider: test_suite + This is a long test case name example containing + more than 80 characters + @Description: This is a test case description + """ + pass + + def test_000016(self): + """ + :title: IDM-IPA-TC: Feature: verify abc user is able to login + :id: test_case_00016 + """ + pass + + def test_000017(self): + """ + :title: IDM-IPA-TC: Feature: verify abc user is able to login + and all the groups user is member is shown in + id command + :id: test_case_00017 + """ + pass +