#10 Add support to generate testcase names for parametrized test cases
Merged 5 years ago by spoore. Opened 5 years ago by mrniranjan.
mrniranjan/pytest-modifyjunit master  into  master

file modified
+7 -1
@@ -64,6 +64,12 @@ 

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

                          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:

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

file added
+7
@@ -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

file modified
+16
@@ -130,3 +130,19 @@ 

          """

          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

+ 

Fixes Issue: #8

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

py.test test_0001 -s -v --junitxml=a.xml shows below output;

~~~~
test_0001.py::TestClass1::IDM-IPA-TC: Feature: verify abc user is able to login and all the groups user is member is shown in id command PASSED
test_0001.py::TestClass1::test_000018[2 users 3 runs]
test_0001.py::TestClass1::IDM-SSSD-TC: Feature: Test performance tests with 2 users 3 runs PASSED
test_0001.py::TestClass1::test_000018[3 users 2 runs]
test_0001.py::TestClass1::IDM-SSSD-TC: Feature: Test performance tests with 3 users 2 runs PASSED
test_0001.py::TestClass1::test_000019[3-8]
test_0001.py::TestClass1::Testing input is less than expected 3-8 PASSED
test_0001.py::TestClass1::test_000019[4-6]
test_0001.py::TestClass1::Testing input is less than expected 4-6 PASSED
~~~~

rebased onto 134daf0

5 years ago

Pull-Request has been merged by spoore

5 years ago