Skip to content

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

Merged
merged 4 commits into from
Jan 6, 2017

Conversation

djarecka
Copy link
Collaborator

@djarecka djarecka commented Jan 4, 2017

  • I left the try/except blocks in test_node_init and test_io_subclass: it looks like the tests should fail only for some exceptions, and others are ok

  • I removed also logger.info('Exception: %s' % str(e)) parts, most other test don't have it anyway. I can bring it back if needed.

@codecov-io
Copy link

codecov-io commented Jan 5, 2017

Current coverage is 72.46% (diff: 100%)

Merging #1773 into master will increase coverage by 0.02%

@@             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          

Powered by Codecov. Last update 7b5201d...6f5939f

# 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:
Copy link
Member

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.

Copy link
Collaborator Author

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).

Copy link
Member

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.

Copy link
Collaborator Author

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.

Copy link
Member

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, understand now

@satra satra merged commit 589659d into nipy:master Jan 6, 2017
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

Successfully merging this pull request may close these issues.

3 participants