#6 Add support for Test case title specified in multiple lines.
Merged 6 years ago by spoore. Opened 6 years ago by mrniranjan.
mrniranjan/pytest-modifyjunit master  into  master

file modified
+28 -5
@@ -41,7 +41,7 @@ 

              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 @@ 

          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:

file modified
+1 -1
@@ -8,7 +8,7 @@ 

  

  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",

file modified
+1 -1
@@ -1,1 +1,1 @@ 

- <?xml version="1.0" encoding="utf-8"?><testsuite errors="0" failures="0" name="pytest" skips="0" tests="9" time="0.016"><testcase classname="test.test_0001.TestClass1" file="test/test_0001.py" line="6" name="IDM-IPA-TC: test suite: test case 0001" time="0.000378847122192"><properties><property name="my-test-id" value="IDM-IPA-TC-test123-tc001"/></properties></testcase><testcase classname="test.test_0001.TestClass1" file="test/test_0001.py" line="13" name="IDM-IPA-TC: test suite: test case 0002" time="0.000261068344116"><properties><property name="my-test-id" value="IDM-IPA-TC-test123-tc002"/></properties></testcase><testcase classname="test.test_0001.TestClass1" file="test/test_0001.py" line="20" name="IDM-IPA-TC: test suite: test case 0003" time="0.000255107879639"><properties><property name="my-test-id" value="IDM-IPA-TC-test123-tc003"/></properties></testcase><testcase classname="test.test_0001.TestClass1" file="test/test_0001.py" line="27" name="IDM-IPA-TC: test suite: test case 0004" time="0.000238180160522"></testcase><testcase classname="test.test_0001.TestClass1" file="test/test_0001.py" line="31" name="test_0005" time="0.000349998474121"><properties><property name="my-test-id" value="IDM-IPA-TC-test123-tc004"/></properties></testcase><testcase classname="test.test_0001.TestClass1" file="test/test_0001.py" line="35" name="IDM-IPA-TC: test suite: test case 0006" time="0.000251054763794"><properties><property name="my-test-id" value="IDM-IPA-TC-test123-tc006"/></properties></testcase><testcase classname="test.test_0001.TestClass1" file="test/test_0001.py" line="42" name="IDM-IPA-TC: test suite: test case 0007" time="0.000255823135376"><properties><property name="my-test-id" value="IDM-IPA-TC-test123-tc007"/></properties></testcase><testcase classname="test.test_0001.TestClass1" file="test/test_0001.py" line="49" name="IDM-IPA-TC: test suite: test case 0008" time="0.000248908996582"><properties><property name="my-test-id" value="IDM-IPA-TC-test123-tc008"/></properties></testcase><testcase classname="test.test_0001.TestClass1" file="test/test_0001.py" line="56" name="IDM-IPA-TC: test suite: test case 0009" time="0.000250101089478"><properties><property name="my-test-id" value="IDM-IPA-TC-test123-tc009"/></properties></testcase></testsuite>

+ <?xml version="1.0" encoding="utf-8"?><testsuite errors="0" failures="0" name="pytest" skips="0" tests="17" time="0.033"><testcase classname="test.test_0001.TestClass1" file="test/test_0001.py" line="6" name="IDM-IPA-TC: test suite: test case 0001" time="0.000306129455566"><properties><property name="my-test-id" value="IDM-IPA-TC-test123-tc001"/></properties></testcase><testcase classname="test.test_0001.TestClass1" file="test/test_0001.py" line="13" name="IDM-IPA-TC: test suite: test case 0002" time="0.000229835510254"><properties><property name="my-test-id" value="IDM-IPA-TC-test123-tc002"/></properties></testcase><testcase classname="test.test_0001.TestClass1" file="test/test_0001.py" line="20" name="IDM-IPA-TC: test suite: test case 0003" time="0.000357627868652"><properties><property name="my-test-id" value="IDM-IPA-TC-test123-tc003"/></properties></testcase><testcase classname="test.test_0001.TestClass1" file="test/test_0001.py" line="27" name="IDM-IPA-TC: test suite: test case 0004" time="0.000256299972534"></testcase><testcase classname="test.test_0001.TestClass1" file="test/test_0001.py" line="31" name="test_0005" time="0.000231742858887"><properties><property name="my-test-id" value="IDM-IPA-TC-test123-tc004"/></properties></testcase><testcase classname="test.test_0001.TestClass1" file="test/test_0001.py" line="35" name="IDM-IPA-TC: test suite: test case 0006" time="0.000214338302612"><properties><property name="my-test-id" value="IDM-IPA-TC-test123-tc006"/></properties></testcase><testcase classname="test.test_0001.TestClass1" file="test/test_0001.py" line="42" name="IDM-IPA-TC: test suite: test case 0007" time="0.000240802764893"><properties><property name="my-test-id" value="IDM-IPA-TC-test123-tc007"/></properties></testcase><testcase classname="test.test_0001.TestClass1" file="test/test_0001.py" line="49" name="IDM-IPA-TC: test suite: test case 0008" time="0.000328302383423"><properties><property name="my-test-id" value="IDM-IPA-TC-test123-tc008"/></properties></testcase><testcase classname="test.test_0001.TestClass1" file="test/test_0001.py" line="56" name="IDM-IPA-TC: test suite: test case 0009" time="0.0002121925354"><properties><property name="my-test-id" value="IDM-IPA-TC-test123-tc009"/></properties></testcase><testcase classname="test.test_0001.TestClass1" file="test/test_0001.py" line="63" name="IDM-SSSD-TC: test provider: test_suite This is a long test case name example containing more than 80 characters" time="0.000375270843506"></testcase><testcase classname="test.test_0001.TestClass1" file="test/test_0001.py" line="71" name="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" time="0.00021505355835"></testcase><testcase classname="test.test_0001.TestClass1" file="test/test_0001.py" line="81" name="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" time="0.000220060348511"></testcase><testcase classname="test.test_0001.TestClass1" file="test/test_0001.py" line="90" name="IDM-SSSD-TC: test provider: test_suite" time="0.000201940536499"></testcase><testcase classname="test.test_0001.TestClass1" file="test/test_0001.py" line="97" name="IDM-IPA-TC: test suite: test case 00014" time="0.000216960906982"></testcase><testcase classname="test.test_0001.TestClass1" file="test/test_0001.py" line="104" name="IDM-SSSD-TC: test provider: test_suite This is a long test case name example containing more than 80 characters" time="0.000211954116821"></testcase><testcase classname="test.test_0001.TestClass1" file="test/test_0001.py" line="113" name="IDM-IPA-TC: Feature: verify abc user is able to login" time="0.000218152999878"></testcase><testcase classname="test.test_0001.TestClass1" file="test/test_0001.py" line="120" name="IDM-IPA-TC: Feature: verify abc user is able to login and all the groups user is member is shown in id command" time="0.000601768493652"></testcase></testsuite> 

\ No newline at end of file

file modified
+67
@@ -60,3 +60,70 @@ 

          :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

+