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

Comments

Projects
None yet
4 participants
@GoogleCodeExporter
Copy link

commented Apr 4, 2015

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

@GoogleCodeExporter

This comment has been minimized.

Copy link
Author

commented Apr 4, 2015

Tyler,

I like the second version

  nosetests-2.7 test_analysis:Test_Helanal

better.

If we can make this work by banning relative imports in the UnitTests (but not 
in the package MDAnalysis itself) then I think we should do so.

Has anyone else arguments for/against?

Oliver

Original comment by orbeckst on 14 Jul 2014 at 7:29

@orbeckst

This comment has been minimized.

Copy link
Member

commented May 24, 2015

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

@tylerjereddy

This comment has been minimized.

Copy link
Member

commented Jun 14, 2015

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

This comment has been minimized.

Copy link
Member

commented Jun 14, 2015

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

This comment has been minimized.

Copy link
Member

commented Jun 14, 2015

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

-added new test_imports.py module to enforce the ban on relative impo…
…rts in unit testing modules (Issue #189)

-manually repaired unit testing modules caught by above unit testing of import statements

tylerjereddy added a commit that referenced this issue Jun 15, 2015

@tylerjereddy

This comment has been minimized.

Copy link
Member

commented Jun 15, 2015

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 referenced this issue Sep 6, 2015

Closed

style guide #404

11 of 11 tasks complete

jbarnoud added a commit to jbarnoud/mdanalysis that referenced this issue Mar 20, 2016

Remove relative imports introduced in MDAnalysis#787
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
You can’t perform that action at this time.