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

ImportError: Import by filename is not supported. #751

Closed
brussee opened this issue May 20, 2016 · 3 comments
Closed

ImportError: Import by filename is not supported. #751

brussee opened this issue May 20, 2016 · 3 comments

Comments

@brussee
Copy link
Contributor

brussee commented May 20, 2016

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)
@inclement
Copy link
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.

@kived
Copy link
Contributor

kived commented May 20, 2016

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.

@brussee
Copy link
Contributor Author

brussee commented May 20, 2016

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.

@brussee brussee closed this as completed May 20, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants