From 134daf017d4f8271d11592180afc20096abb03f1 Mon Sep 17 00:00:00 2001
From: Niranjan M.R <mrniranjan@redhat.com>
Date: May 21 2018 14:21:22 +0000
Subject: Add support to generate testcase names for parametrized test cases


Minor review fixes

Fixes Issue: #8

Signed-off-by: Niranjan M.R <mrniranjan@redhat.com>

---

diff --git a/pytest_modifyjunit/plugin.py b/pytest_modifyjunit/plugin.py
index 0aab9d0..a7772d7 100644
--- a/pytest_modifyjunit/plugin.py
+++ b/pytest_modifyjunit/plugin.py
@@ -64,6 +64,12 @@ class ModifyJunit(object):
         outcome = yield
         rep = outcome.get_result()
         title_regex = re.compile("^.[T|t]itle\s*:\s*.*")
+        try:
+            test_ids = item.__dict__['callspec']._idlist
+        except KeyError:
+            test_params = ''
+        else:
+            test_params = ''.join(test_ids)
         if item._obj.__doc__:
             doc_strings = item._obj.__doc__.strip()
             doc_list = re.sub('(\n\s*[:|@][A-Za-z0-9_-]*:)', '\n\\1',
@@ -92,7 +98,7 @@ class ModifyJunit(object):
                         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)
+                    tc_name = re.sub("^.[T|t]itle\s*:\s*", "", tc_title + ' ' + test_params)
             rep.nodeid = '::'.join(rep.nodeid.split('::')[0:-1]) + \
                          '::' + tc_name
         if 'call' in rep.when:
diff --git a/test/a.xml b/test/a.xml
index dd33ba1..33356a9 100644
--- a/test/a.xml
+++ b/test/a.xml
@@ -1 +1 @@
-<?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
+<?xml version="1.0" encoding="utf-8"?><testsuite errors="0" failures="0" name="pytest" skips="0" tests="21" time="0.061"><testcase classname="test.test_0001.TestClass1" file="test/test_0001.py" line="9" name="IDM-IPA-TC: test suite: test case 0001 " time="0.000505924224854"><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="16" name="IDM-IPA-TC: test suite: test case 0002 " time="0.000391960144043"><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="23" name="IDM-IPA-TC: test suite: test case 0003 " time="0.000375986099243"><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="30" name="IDM-IPA-TC: test suite: test case 0004" time="0.000391721725464"></testcase><testcase classname="test.test_0001.TestClass1" file="test/test_0001.py" line="34" name="test_0005" time="0.000383853912354"><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="38" name="IDM-IPA-TC: test suite: test case 0006 " time="0.000384092330933"><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="45" name="IDM-IPA-TC: test suite: test case 0007 " time="0.000592947006226"><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="52" name="IDM-IPA-TC: test suite: test case 0008 " time="0.000892877578735"><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="59" name="IDM-IPA-TC: test suite: test case 0009 " time="0.0005202293396"><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="66" name="IDM-SSSD-TC: test provider: test_suite This is a long test case name example containing more than 80 characters " time="0.000585079193115"></testcase><testcase classname="test.test_0001.TestClass1" file="test/test_0001.py" line="74" 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.00071382522583"></testcase><testcase classname="test.test_0001.TestClass1" file="test/test_0001.py" line="84" 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.000701904296875"></testcase><testcase classname="test.test_0001.TestClass1" file="test/test_0001.py" line="93" name="IDM-SSSD-TC: test provider: test_suite " time="0.000392198562622"></testcase><testcase classname="test.test_0001.TestClass1" file="test/test_0001.py" line="100" name="IDM-IPA-TC: test suite: test case 00014 " time="0.000381946563721"></testcase><testcase classname="test.test_0001.TestClass1" file="test/test_0001.py" line="107" name="IDM-SSSD-TC: test provider: test_suite This is a long test case name example containing more than 80 characters " time="0.000390768051147"></testcase><testcase classname="test.test_0001.TestClass1" file="test/test_0001.py" line="116" name="IDM-IPA-TC: Feature: verify abc user is able to login " time="0.000467777252197"></testcase><testcase classname="test.test_0001.TestClass1" file="test/test_0001.py" line="123" 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.00120186805725"></testcase><testcase classname="test.test_0001.TestClass1" file="test/test_0001.py" line="131" name="IDM-SSSD-TC: Feature: Test performance tests with 2 users 3 runs" time="0.000566959381104"></testcase><testcase classname="test.test_0001.TestClass1" file="test/test_0001.py" line="131" name="IDM-SSSD-TC: Feature: Test performance tests with 3 users 2 runs" time="0.000509977340698"></testcase><testcase classname="test.test_0001.TestClass1" file="test/test_0001.py" line="137" name="Testing input is less than expected 3-8" time="0.000570774078369"></testcase><testcase classname="test.test_0001.TestClass1" file="test/test_0001.py" line="137" name="Testing input is less than expected 4-6" time="0.000583171844482"></testcase></testsuite>
\ No newline at end of file
diff --git a/test/conftest.py b/test/conftest.py
new file mode 100644
index 0000000..e1484b4
--- /dev/null
+++ b/test/conftest.py
@@ -0,0 +1,7 @@
+import pytest
+
+data = [[2, 3], [3, 2]]
+
+@pytest.fixture(params=data, ids=["2 users 3 runs", "3 users 2 runs"])
+def load_data(request):
+    return request.param
diff --git a/test/test_0001.py b/test/test_0001.py
index 7c3eb9b..54eebd9 100644
--- a/test/test_0001.py
+++ b/test/test_0001.py
@@ -130,3 +130,19 @@ class TestClass1(object):
         """
         pass
 
+    def test_000018(self, load_data):
+        """
+        :title: IDM-SSSD-TC: Feature: Test performance tests with
+        """
+        pass
+
+    @pytest.mark.parametrize("test_input, expected", [
+        (3, 8),
+        (4, 6),
+        ])
+    def test_000019(self, test_input, expected):
+        """
+        :title: Testing input is less than expected
+        """
+        assert test_input < expected
+

