Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scrubbing out XML character in the generated test names #4

Closed
dlai0001 opened this issue Jan 11, 2013 · 4 comments
Closed

Scrubbing out XML character in the generated test names #4

dlai0001 opened this issue Jan 11, 2013 · 4 comments

Comments

@dlai0001
Copy link

Currently if I passing in Objects using the decorator, because the "name" attribute can take on "<" and ">" characters if value passed in is an object (using default repr() ). This will cause the JUnit parser to break if you use JUnit parser in CI. Can you please add some sort of XML chracter stripping or escaping in the @DDT annotation class.

    for name, f in cls.__dict__.items():
        if hasattr(f, MAGIC):
            i = 0
            for v in getattr(f, MAGIC):
                test_name = getattr(v, "__name__", "{0}_{1}".format(name, v))
                #strip illegal xml characters characters. - DL
                formatted_test_name = re.sub(r'[<>&/]', '', test_name)
                setattr(cls, formatted_test_name, feed_data(f, v))
                i = i + 1
            delattr(cls, name)
    return cls
@txels
Copy link
Collaborator

txels commented Jan 22, 2013

I am not sure about this. By default this code has no idea whether it is running somewhere that will parse its output and put it inside XML files unescaped. So I believe it is the fault of the software that generates XML not to escape this. Which test runner are you using?

OTOH most runners probably expect this to be a method name and thus XML-safe, so they don't care.

Not sure I will feel this compelling enough to do the work myself, but if you send this as a PR with a proper unit test I will merge it and release it.

@dlai0001
Copy link
Author

I'm using nose as my test runner. I'm not too familiar with the internals of the unittest runner to write a proper unit test for this.

What's happening is the data is being used to generate the names used in the xml test results, the data is used as part of the test name, since the names in the unittest results are of the from of "name_of_the_method_THETESTDATA" so alot of my unit test results were looking like,

<?xml version="1.0" encoding="UTF-8"?>
<testsuite name="tests" tests="3" errors="0" failures="0" time="37.787">
<testcase classname="tests.logintests" name="TestLogin.TestLogin.test_login_<LoginTestData(user:badusername, passwd:password, expected:False)>" time="10.894"/>
<testcase classname="tests.logintests" name="TestLogin.TestLogin.test_login_<LoginTestData(user:user1, passwd:badpassword, expected:False)>" time="7.205"/>
<testcase classname="tests.logintests" name="TestLogin.TestLogin.test_login_<LoginTestData(user:user1, passwd:password, expected:True)>" time="19.686"/>
<system-out><![CDATA[]]></system-out><system-err><![CDATA[]]></system-err>
</testsuite>

The XML characters in the 'name' property causes the JUnit Parser plugins on Jenkins and Bamboo to fail.

@txels
Copy link
Collaborator

txels commented Jan 23, 2013

Thanks for further illustrating the issue. Makes sense to me. Will take your PR if you send one, or else may give it some time later this week.

@txels
Copy link
Collaborator

txels commented Mar 20, 2014

This has now been addressed in #18.
It took a while :]

@txels txels closed this as completed Mar 20, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants