From 134daf017d4f8271d11592180afc20096abb03f1 Mon Sep 17 00:00:00 2001 From: Niranjan M.R 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 --- 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 @@ - \ No newline at end of file + \ 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 +