-
Notifications
You must be signed in to change notification settings - Fork 532
simplifying tests, removing some try/except blocks #1773
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
Conversation
Current coverage is 72.46% (diff: 100%)@@ master #1773 diff @@
==========================================
Files 1056 1056
Lines 52745 52696 -49
Methods 0 0
Messages 0 0
Branches 7663 7663
==========================================
- Hits 38208 38187 -21
+ Misses 13326 13298 -28
Partials 1211 1211
|
# create dummy distributed plugin class | ||
from nipype.pipeline.plugins.base import DistributedPluginBase | ||
|
||
class RaiseError(DistributedPluginBase): | ||
def _submit_job(self, node, updatehash=False): | ||
raise Exception('Submit called') | ||
try: | ||
|
||
with pytest.raises(Exception) as excinfo: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we make this a specific exception, but changing what exception is raised. here it could be a specific exception, like EngineTestException
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if I understand. Do you want pytest to check specific exceptions or you want to define a class EngineTestException(Exception)
.
I sometimes ask pytest to check a specific error or exception, but in this case the exception from line 517 was raised (i.e. raise Exception('Submit called')
), so to be more specific I could only check the message and I've done it in the line 521 assert 'Submit called' == str(excinfo.value)
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in this particular case define a specific class and check for that. we shouldn't raise generic exceptions unless absolutely necessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, can do it, but the class RaiseError(DistributedPluginBase)
is defined within the test function, so it will only influence this specific test and not the general code behavior.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
correct. most of nipype is ok - we have a couple of general exception catches, mostly because we don't know how python functions or external tools called via subprocess are going to crash
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, understand now
I left the try/except blocks in
test_node_init
andtest_io_subclass
: it looks like the tests should fail only for some exceptions, and others are okI removed also
logger.info('Exception: %s' % str(e))
parts, most other test don't have it anyway. I can bring it back if needed.