-
-
Notifications
You must be signed in to change notification settings - Fork 31.1k
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
unittest.py patch: add skipped test functionality #40949
Comments
I added the possibility for tests using the unittest.py TestCase.skip(msg): skips test unconditionally These can be called either in setUp() or in the test I am using Python 2.3.3, so the changes are against the Quick usage example: class ReadShadowTest(unittest.TestCase):
"""Read access to /etc/shadow"""
def testReadingAsRoot(self):
"""Reading /etc/shadow as root"""
self.skipIf(os.geteuid() != 0, "Must be root")
open("/etc/shadow").close() The example program produces the following output: $ ./SkippedTestDemo.py -v
Access to autoexec.bat ... SKIPPED (Only available on
Windows)
Access to config.sys ... SKIPPED (Only available on
Windows)
Reading /etc/shadow as root ... SKIPPED (Must be root)
Reading /etc/shadow as non-root ... ok
-------------------------------------------------------
Ran 4 tests in 0.004s OK (skipped=3) |
Logged In: YES Will this muck up some the existing test runners that people |
Logged In: YES I don't think so. Basically, the patch changes the following:
I see two potential problems:
However, to use the test-skipping functionality, custom test runners will OTOH, I don't have a big test codebase to check. I read that e.g. Zope is |
Logged In: YES The test suite for the added functionality. |
Logged In: YES Added sample code. |
Logged In: YES This is a nice patch. I am wondering if it can be extended |
Logged In: YES The skipIf() method is sufficient. From there, it is |
Logged In: YES I'd certainly find such a feature handy - when testing Ditto for the original example of cross-platform testing. |
Logged In: YES After more thought, I think decorators offer a cleaner, more def rootonly(f):
"Decorator to skip tests that require root access"
if os.geteuid() == 0:
return f
return lambda self: 0
@rootonly
def testReadingAsRoot(self):
. . . Note the rootonly() decorator need only be defined once |
Logged In: YES I strongly disagree. Skipped tests should not just be The Python regression tests (although I'm not familiar with The decorator approach is an interesting idea, though, and def rootOnly(f):
"""Decorator to skip tests that require root access"""
def wrapper(self):
self.skipIf(os.getuid() != 0, "Must be root")
self.f()
wrapper.__doc__ = f.__doc__
return wrapper
class ReadShadowTest(unittest.TestCase):
"""Read access to /etc/shadow"""
@rootOnly
def testReadingAsRoot(self):
"""Reading /etc/shadow as root"""
open("/etc/shadow").close() Note that I'm not yet familiar with decorators, so the |
Logged In: YES I've been really tied up; sorry for the delayed response, but I've been Overall, I'm leaning in favour of accepting this patch, probably with The concept of skipping is one that has been kept out of JUnit, but is I agree with Remy that the decorator example, though ingenious, has Please give me a few more days on this, and I'll work on integrating |
Logged In: YES Speaking of decorators, the NUnit example is quite And if I'm not mistaken all of this can be added without Interesting times lay ahead! |
Logged In: YES Yes, that's right, and I would consider providing a number of such Categories are particularly interesting. In theory, it would be possible Skipping is not quite the same as ignoring, since it's determined at Interesting times indeed. |
Logged In: YES I have just run the unit tests from Zope 2.7.2 (2358 tests) on That may give a hint about backward compatibility. |
Logged In: YES Anything new about skipping tests? I'm still very interested. |
So what's the status of this? Skipping test is still an important |
The status of this ticket is unchanged. I'm somewhat removed from the I still believe this would be a beneficial change to the unittest |
I'll take it. |
Hello, The attached patch adds the skip functionality and tests to a very I think the whole thing is missing documentation, which I would gladly Thanks. |
Oh, I forgot to upgrade versions to include Python 3.0 and to mention |
Pupeno's patch looks good to me. Additional candy would be a decorator |
There's still a typo in the docstring of TestResult.addSkipped() (tuble |
I think this is a good improvement, and I hope it can make it into 2.7/3.1. Several comments on patch:
(Georg, I hope you don't mind if I "steal" this from you.) |
Ok, here's my unittest skipping patch. It supports skipping classes and I had to employ a little evil to make test skipping work for classes. |
Here's the patch on Rietveld: http://codereview.appspot.com/27095 |
I've attached a new patch which takes into account Antoine's review. |
Committed my patch in r70555. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: