From cea93f37dcba0af6efe6bb86c803d09f03772526 Mon Sep 17 00:00:00 2001 From: Abhijeet Kasurde Date: Jul 27 2017 12:15:27 +0000 Subject: Remove hardcoding from testcase title Signed-off-by: Abhijeet Kasurde --- diff --git a/pytest_modifyjunit/plugin.py b/pytest_modifyjunit/plugin.py index 2439e44..985f380 100644 --- a/pytest_modifyjunit/plugin.py +++ b/pytest_modifyjunit/plugin.py @@ -4,6 +4,7 @@ This module adds a new marker @xmlprops which addes additional properties to a test class in junit xml. Also modifies testcase name with the @Title specified test case docstrings """ +import re import pytest __all__ = [ @@ -58,11 +59,12 @@ class ModifyJunit(object): """ Fetch the title from docstrings during call phase """ outcome = yield 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'): - if '@Title:' in line: - tc_name = line.strip().replace("@Title: ", "", 1) + if title_regex.match(line): + tc_name = re.sub("^.[T|t]itle\s*:\s*", "", line) break rep.nodeid = '::'.join(rep.nodeid.split('::')[0:-1]) + \ '::' + tc_name diff --git a/test/__pycache__/test_0001.cpython-27-PYTEST.pyc b/test/__pycache__/test_0001.cpython-27-PYTEST.pyc deleted file mode 100644 index d2c78b8..0000000 Binary files a/test/__pycache__/test_0001.cpython-27-PYTEST.pyc and /dev/null differ diff --git a/test/a.xml b/test/a.xml index 9fb47fb..9a8e387 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 8dac040..d082b4c 100644 --- a/test/test_0001.py +++ b/test/test_0001.py @@ -33,3 +33,30 @@ class TestClass1(object): def test_0005(self): pass + @pytest.mark.xmlprop("my-test-id", "IDM-IPA-TC-test123-tc006") + def test_0006(self): + """ + :Title: IDM-IPA-TC: test suite: test case 0006 + """ + pass + + @pytest.mark.xmlprop("my-test-id", "IDM-IPA-TC-test123-tc007") + def test_0007(self): + """ + :title: IDM-IPA-TC: test suite: test case 0007 + """ + pass + + @pytest.mark.xmlprop("my-test-id", "IDM-IPA-TC-test123-tc008") + def test_0008(self): + """ + :Title : IDM-IPA-TC: test suite: test case 0008 + """ + pass + + @pytest.mark.xmlprop("my-test-id", "IDM-IPA-TC-test123-tc009") + def test_0009(self): + """ + :title : IDM-IPA-TC: test suite: test case 0009 + """ + pass