Closed dougthor42 closed 7 years ago
Wow! Thanks for the thorough write-up.
This was a tricky issue. It all boiled down to Python treating a SkipTest
exception raised during setUpClass
as a class setup failure. Which it is not. In some versions of Python that meant this got reported as a mysterious setup error without indicating which module/class/test caused it. Other versions of Python caught it later and marked it as a single skip of the class.
To fix this I chose to override the exception-handling of the code that runs setUpClass
and actually handle the special case of SkipTest
being raised, as the unittest module itself ought to have done in the first place. This results in each test independently being reported as being skipped, which I think is the most sane behavior. Edit: More to the point, this makes it so that raising SkipTest
is handled the same way as if the class were decorated. The fact that the unittest
module wasn't handling it in the same way was the cause of the bug in the first place.
$ ./g -vvv green_skiptest_error
Green 2.8.2, Coverage 4.3.4, Python 2.7.13
green_skiptest_error
TestMe
s test_me -- Intentionally throwing SkipTest exception
s test_me_too -- Intentionally throwing SkipTest exception
Skipped green_skiptest_error.TestMe.test_me - Intentionally throwing SkipTest exception
Skipped green_skiptest_error.TestMe.test_me_too - Intentionally throwing SkipTest exception
Ran 2 tests in 0.112s
OK (skips=2)
This fix is included in version 2.8.2 (just released).
Yup, that looks to have cleared things up!
Thanks a bunch.
Hello, I've encountered a similar issue on the Yocto Project with a particular QA test. It doesn't look like unittest has been tweaked to incorporate fixes similar to yours. Do you have any plans to submit a fix for this upstream for unittest?
@threexc The thought hadn't occurred to me!
I created https://github.com/CleanCut/green/issues/215 to track contributing the fix to upstream, but I have no idea when I'll be able to get to it. I included a link to the actual few lines that are the fix, so if you or anyone else would like to have the fun of contributing it upstream, please go ahead! 😄
Summary
It appears that green is not handling raised
unittest.SkipTest
exceptions insetUpClass()
as expected. It's silently skipping the entire class instead of verbosely skipping them.Steps to Reproduce
Make this file:
and then run:
Actual
Expected
For comparison, here's the output of
nose2 green_skiptest_error -vvv
andpython green_skiptest_error.py
:Versions
Listed in all the code snippets, but here they are anyway:
Investigation
If
SkipTest
is raised inside a test method rather than thesetUpClass
method, then things work as expected:Throwing
SkipTest
insidesetUp
works correctlyComments
When an entire class is skipped, the skip message should be listed on the class output and the test output. Example (colors are simply listed in square brackets at the end of the line):
(However, this probably should be a separate issue/feature request)