nose-devs / nose

nose is nicer testing for python
http://readthedocs.org/docs/nose/en/latest/
1.36k stars 394 forks source link

xUnit test name doesn't use "description" attribute of yielded function #545

Open devcooch opened 11 years ago

devcooch commented 11 years ago

Hello,

When we are using generators for test generation, xUnit plugin doesn't consider "description" attribute of yielded function. Please see example:

===== test.py =========
def check_int(i):
    assert i < 10

def test_me():
    for i in xrange(10):
        check_int.description = "Check integer %d" % i
        yield check_int, i

====== command line =========
nosetests --verbose --with-xunit
Check integer 0 ... ok
Check integer 1 ... ok
Check integer 2 ... ok
Check integer 3 ... ok
Check integer 4 ... ok
Check integer 5 ... ok
Check integer 6 ... ok
Check integer 7 ... ok
Check integer 8 ... ok
Check integer 9 ... ok
----------------------------------------------------------------------
XML: nosetests.xml
----------------------------------------------------------------------
Ran 10 tests in 0.006s

OK

===== ACTUAL nosetests.xml ========

<?xml version="1.0"?>
<testsuite name="nosetests" tests="11" errors="0" failures="0" skip="0">
  <testcase classname="test" name="test_me(0,)" time="0.000"/>
  <testcase classname="test" name="test_me(1,)" time="0.000"/>
  <testcase classname="test" name="test_me(2,)" time="0.000"/>
  <testcase classname="test" name="test_me(3,)" time="0.000"/>
  <testcase classname="test" name="test_me(4,)" time="0.000"/>
  <testcase classname="test" name="test_me(5,)" time="0.001"/>
  <testcase classname="test" name="test_me(6,)" time="0.001"/>
  <testcase classname="test" name="test_me(7,)" time="0.001"/>
  <testcase classname="test" name="test_me(8,)" time="0.000"/>
  <testcase classname="test" name="test_me(9,)" time="0.001"/>
  <testcase classname="test" name="test2" time="0.000"/>
</testsuite>
====== EXPECTED nosetests.xml ===========
<?xml version="1.0"?>
<testsuite name="nosetests" tests="11" errors="0" failures="0" skip="0">
  <testcase classname="Check integer 0" name="Check integer 0" time="0.002"/>
  <testcase classname="Check integer 1" name="Check integer 1" time="0.001"/>
  <testcase classname="Check integer 2" name="Check integer 2" time="0.000"/>
  <testcase classname="Check integer 3" name="Check integer 3" time="0.000"/>
  <testcase classname="Check integer 4" name="Check integer 4" time="0.001"/>
  <testcase classname="Check integer 5" name="Check integer 5" time="0.000"/>
  <testcase classname="Check integer 6" name="Check integer 6" time="0.001"/>
  <testcase classname="Check integer 7" name="Check integer 7" time="0.000"/>
  <testcase classname="Check integer 8" name="Check integer 8" time="0.001"/>
  <testcase classname="Check integer 9" name="Check integer 9" time="0.000"/>
  <testcase classname="test" name="test2" time="0.001"/>
</testsuite>

I will be happy to provide patch, I already have it. I run unit tests on py27 and py32, looks like nothing broken. I haven't managed to run other tests as I don't succeeded to configure proper environment for that.

Regards, Dmitry

JonathanRRogers commented 11 years ago

I would also like my Xunit output to use the customized description. Is your patch available somewhere?

devcooch commented 11 years ago

Hi Jonathan, I'll merge my fix with latest version and try to send pull request. Though it looks like the nose developers are not really reading everything in the project.

jszakmeister commented 11 years ago

FWIW, I've looked at this and I can't decide if this is appropriate. JUnit output typically has the classname point to the parent of the method, and then use the name field to hold the method name. It's nice to have a description, but I think giving up the name of the method is too much. There's also no wiggle room in the JUnit spec for another attribute to contain this information. I think losing the organization for the description is a net negative. Perhaps changing the name field (not classname) to something like:

methodName (Description goes here)

Thoughts?

And FWIW, I only know of myself and Jason who are working on Nose at all, and both of us have fulltime jobs. Jason has about 15 minutes a week for Nose, and I think has been more focused on Nose2 (which is coming along well, BTW). As for me, I've been pretty tied up with work too. When I start hitting 50-60 hours a week, it leaves little time for anything else. I hope you understand.

devcooch commented 11 years ago

Hi John!

I am apologizing if my comment was too rude. Sure all of us are working in normal fulltime jobs, same for me. And actually I am a big fan of Nose.

Speaking about the description usage: Now I see your point, so probably I had a bit different understanding of it. What if we will just introduce support for additional function attributes instead of reusing description? So user can intentionally override xUnit plugin output? To give more details - we are using Jenkins to collect nose results and I am using nose as convenient test runner, so if I use default yield naming scheme the results are really unreadable. So what I want is to put some really understandable name for the method instead of generated one.

Please let me know what do you think and thanks for your answer!

Regards, Dmitry

jszakmeister commented 11 years ago

No worries Dmitry, your comment wasn't rude. I just wanted to explain why you see little activity on Nose.

I'm just thinking out loud here: what happens if you do embed the description field as the name only (not the classname)? One issue I can think of would be is when using coverage support. You can't use the name field to locate the method in that case. But, that doesn't matter with generators, because you aren't currently going to get those to match now anyways (because it embeds a stringified version of the parameters). So, what if we just changed the name field and not the class name one? That would at least help keep things fairly organized when you have lots of tests, but see the description too.

BTW, I do think it's fine to reuse the description attribute. My only real concern is breaking CI tools other than just Jenkins, like QuickBuild. I'd like to enable this only with an option though. Maybe --xunit-use-desc?

NickeZ commented 9 years ago

We have a similar issue, but if we could change the name-attribute to the name of the yielded function that would be a better description of the actual test case. We have test generators that yield several different functions but use the same input for the tests.

rsxrox commented 9 years ago

Hi - can you kindly let me know if there's any update on this requirement? This will be useful for me too.