The company I work for uses and loves PyDev and PyDev extensions! One of the features we love is the auto imports and organize imports. Unfortunately, we've run into a slight problem with it recently that makes these features quite frustrating: handling the case when import order matters.
In our case, we are trying to write unit tests against our Django backed application. We don't want to use Django's unit test framework (which are really integration or system level tests), but instead use the standard Python unit tests. We've figured out how to "trick" Django into not requiring a database, but it requires that our code to alter Django be imported _before_ anything that relies on any Django code.
To do so, we can put the import at the top of our test module, and if we put that import in an "if True:" block, it even works fine when we organize imports. Unfortunately, when a new import is added by the auto-import feature, it's added _above_ our "if True:" block, and any subsequent organize import command causes all the other imports to be shifted up to where this new import is, before our "if True:" block.
Is there any way we can get a way to tell PyDev where to add imports on auto import?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Not currently... What would you think about having a comment
#@ImportSection
And Pydev would locate that and would always put new imports after it (and when organizing imports, it wouldn't change the order of the ones above that tag)?
Please add that as a feature request.
Cheers,
Fabio
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The company I work for uses and loves PyDev and PyDev extensions! One of the features we love is the auto imports and organize imports. Unfortunately, we've run into a slight problem with it recently that makes these features quite frustrating: handling the case when import order matters.
In our case, we are trying to write unit tests against our Django backed application. We don't want to use Django's unit test framework (which are really integration or system level tests), but instead use the standard Python unit tests. We've figured out how to "trick" Django into not requiring a database, but it requires that our code to alter Django be imported _before_ anything that relies on any Django code.
To do so, we can put the import at the top of our test module, and if we put that import in an "if True:" block, it even works fine when we organize imports. Unfortunately, when a new import is added by the auto-import feature, it's added _above_ our "if True:" block, and any subsequent organize import command causes all the other imports to be shifted up to where this new import is, before our "if True:" block.
Is there any way we can get a way to tell PyDev where to add imports on auto import?
Not currently... What would you think about having a comment
#@ImportSection
And Pydev would locate that and would always put new imports after it (and when organizing imports, it wouldn't change the order of the ones above that tag)?
Please add that as a feature request.
Cheers,
Fabio
That sounds great!
I've added the feature request here: https://sourceforge.net/tracker/index.php?func=detail&aid=2514166&group_id=85796&atid=577332.
Thanks!
--Chris