Skip to content

relative imports and nosetests #189

Closed

Description

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

Activity

  1. added this to the 0.11 milestone on May 24, 2015
  2. orbeckst commented on May 24, 2015

    @orbeckst
    Member

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

  3. tylerjereddy commented on Jun 14, 2015

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

  4. orbeckst commented on Jun 14, 2015

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

  5. richardjgowers commented on Jun 14, 2015

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

  6. tylerjereddy commented on Jun 15, 2015

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions