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

_setUp() convention no longer allows a fixture to skip a test #31

Open
zzzeek opened this issue Jun 28, 2016 · 2 comments
Open

_setUp() convention no longer allows a fixture to skip a test #31

zzzeek opened this issue Jun 28, 2016 · 2 comments

Comments

@zzzeek
Copy link

zzzeek commented Jun 28, 2016

A fixture might be trying to grab a not-necessarily-available resource, like a database connection. The fixture should be able to invoke skipTest(). This was possible when overriding the setUp() method, but in the new _setUp() convention, all exception are caught including skip exceptions. Fixture should have a skip() method and setUp() should handle this special exception as a skip for the test overall.

@rbtcollins
Copy link
Member

So the issue here is that if you raise an exception of type X, it gets masked to type MultipleExceptions; and test runners don't generally know how to unpack that.

Its plausible that we could teach them one by one, but it would be better to not mask the type. The reason we mask the type is because we need to add additional information beyond the original exception to deal with the general case of an exception circumstance with details captured in the fixture's details that are important.

This is still arguably important for SkipTest debugging, though folk can probably work around that if they have to.

I think something like this would work:

   raise fixtures.OriginalException(unittest2.SkipTest('MySQL not installed'))

With a matching change to setUp to examine err, and if it is an OriginalException, only raise the original exception, accepting that we're going to discard information.

Regarding your proposed approach - adding a skip method - fixtures are not test code [though that is one important use case for them] - adding skip() wouldn't fit well, and it would also have the problem of having to choose which test framework's skip exception to raise - and there are so many :(.

@zzzeek
Copy link
Author

zzzeek commented Jun 29, 2016

somewhere in oslo.db we are doing a thing where we just specify actual exception classes to pass through, on another exception-handling structure. A hook method such as "shouldPassThrough(exception_class)" on Fixture could achieve this.

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