Skip to content

ImportError: Import by filename is not supported. #751

Closed

Description

@brussee

While running nose that uses python unittest builtin library.

Error log:

I/python: AND: Ran string
I/python: Run user program, change dir and execute entrypoint
I/Triblerd: Traceback (most recent call last):
I/Triblerd:   File "Triblerd.py", line 33, in <module>
I/Triblerd:     Triblerd().test()
I/Triblerd:   File "Triblerd.py", line 29, in test
I/Triblerd:     nose.run('-s ' + test_path)
I/Triblerd:   File "/data/user/0/org.tribler.android/files/lib/python2.7/site-packages/nose/core.py", line 301, in run
I/Triblerd:     return TestProgram(*arg, **kw).success
I/Triblerd:   File "/data/user/0/org.tribler.android/files/lib/python2.7/site-packages/nose/core.py", line 121, in __init__
I/Triblerd:     **extra_args)
I/Triblerd:   File "/data/user/0/org.tribler.android/files/lib/python27.zip/unittest/main.py", line 77, in __init__
I/Triblerd: ImportError: Import by filename is not supported.
I/python: Python for android ended.

main.py source:
def __init__(self, module='__main__', defaultTest=None, argv=None,
                testRunner=None, testLoader=loader.defaultTestLoader,
                exit=True, verbosity=1, failfast=None, catchbreak=None,
                buffer=None):
    if isinstance(module, basestring):
        self.module = __import__(module)

Activity

  1. inclement commented on May 20, 2016

    @inclement
    Member

    I wasn't aware of p4a doing anything that would break normal behaviour, though I could have forgotten about a patch doing that. Weird.

  2. kived commented on May 20, 2016

    @kived
    Contributor

    Actually, I don't think we're doing anything to break this. Using __import__ on a filename just isn't supported in general (at least in py2). On Ubuntu 16.04, Python 2.7.11:

    In [1]: __import__('a/b/c.py')
    ---------------------------------------------------------------------------
    ImportError                               Traceback (most recent call last)
    <ipython-input-1-61d17bad1646> in <module>()
    ----> 1 __import__('a/b/c.py')
    
    ImportError: Import by filename is not supported.
    
    
  3. brussee commented on May 20, 2016

    @brussee
    ContributorAuthor

    Exactly. No fault of p4a at all! The issue was on python itself not supporting import by filename. I have worked around this.
    Thanks a lot for your quick responses! I really appreciate it.

    I will add a nose recipe soon, but before I can I have to figure out why the test module could be loaded but the test function inside it is not detected and nose ends with saying 0 tests executed.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions