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

relative imports and nosetests #189

Closed
GoogleCodeExporter opened this issue Apr 4, 2015 · 6 comments
Closed

relative imports and nosetests #189

GoogleCodeExporter opened this issue Apr 4, 2015 · 6 comments

Comments

@GoogleCodeExporter
Copy link

Currently have to do: nosetests-2.7 test_analysis.py:Test_Helanal

and not: nosetests-2.7 test_analysis:Test_Helanal

because of a relative import problem. Since the wiki docs advertise the version 
without the .py, it is perhaps suitable to have a consistent policy on whether 
we will allow Python relative imports in unit test modules. It seems that we 
can mostly work around relative imports, except for things that were placed in 
the testing __init__.py

Original issue reported on code.google.com by tyler.je.reddy@gmail.com on 8 Jul 2014 at 7:39

@orbeckst
Copy link
Member

I'd like to have a consistent policy on how to run the tests.

@tylerjereddy
Copy link
Member

This is a tricky one. It is also worth noting that the wiki indicates that one can invoke all the tests from the command line at the path MDAnalysis/tests by typing nosetests, but this is not the case for me, at least on OS X, even if specifying the --exe flag.

Perhaps that was written before the tests were placed in a separate package? In any case, it seems that the direct command line invocation of nosetests is most appropriately performed at the /testsuite/MDAnalysisTests path, so the wiki should probably be updated to reflect that (shall I open a separate issue for that?).

There are various blog posts and stackoverflow threads about the original issue discussed in this thread. They are mostly focused on invoking python with the -m flag or altering package __init__.py and __all__ structures. I'll see what I can do about it.

@orbeckst
Copy link
Member

Hi Tyler,

On 14 Jun, 2015, at 01:36, Tyler Reddy wrote:

Perhaps that was written before the tests were placed in a separate package? In any case, it seems that the direct command line invocation of nosetests is most appropriately performed at the/testsuite/MDAnalysisTests path, so the wiki should probably be updated to reflect that (shall I open a separate issue for that?).

Just update the wiki to reflect what currently works.

If you (or anyone else) feels the other way should work, raise an issue.

Thanks,
Oliver

@richardjgowers
Copy link
Member

So the way Travis runs tests is just running nosetests from the root of the repo (one up from either package or testsuite), I've just checked and this works for me from ubuntu. Could just be an OSX quirk?

tylerjereddy added a commit that referenced this issue Jun 15, 2015
…rts in unit testing modules (Issue #189)

-manually repaired unit testing modules caught by above unit testing of import statements
@tylerjereddy
Copy link
Member

Relative imports are now banned in all MDAnalysis unit testing modules, and have been replaced accordingly. A new testing module will cause the unit testing suite to issue a FAIL if any module contains a line of code with 'from .' and 'import' strings. By substituting the absolute import statements in place of the relative import statements individual tests can now be performed using either of the call signatures originally described in this issue without problems. Absolute imports are also arguably more clear / explicit. So, I'm closing this issue.

Yes, you may run nosetests from the root of the repo or from /testsuite/MDAnalysisTests, but the method on the wiki no longer seems to work.

@orbeckst orbeckst mentioned this issue Sep 6, 2015
11 tasks
jbarnoud added a commit to jbarnoud/mdanalysis that referenced this issue Mar 20, 2016
We prohibit relative imports in the tests (see MDAnalysis#189). When adding tests
for the dynamic author list (MDAnalysis#787), I introduced some such relative
imports.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants