I am working with Python 3.3.1
64 bit on Ubuntu 13.04
64 bit running under Eclipse 4.3
64 bit with Pydev 2.7.6
in a virtualenv
environment. I have my project in the following directory structure.
Dictionary
|
----------------------------
| |
src test
| |
petaapan petaapan
| | | |
__init__.py logging __init__.py logging
| | | |
__init__.py mplogging.py __init__.py test_mplogging.py
When I try to run test_mplogging.py
using pytest
as the test runner I get the following results:
pydev debugger: starting
============================= test session starts ==============================
platform linux -- Python 3.3.1 -- pytest-2.3.5
plugins: pep8, cache
collected 0 items / 1 errors
==================================== ERRORS ====================================
______________________ ERROR collecting test_mplogging.py ______________________
File "/home/jonathan/UC/Git Repositories/isiiwesuu/Dictionary/tests/petaapan/logging/test_mplogging.py", line 11
in <module>
> import petaapan.logging.mplogging as ml
E ImportError: No module named 'petaapan.logging.mplogging'
My sys.path
has Dictionary/test
ahead of Dictionary/src
so the test tree is searched first and it looks as though that is why the import failed with regular packages.
My next attempt was to do the same using namespace packages, so I removed all the __init__.py
files and got the following results:
pydev debugger: starting
============================= test session starts ==============================
platform linux -- Python 3.3.1 -- pytest-2.3.5
plugins: pep8, cache
collected 0 items / 1 errors
==================================== ERRORS ====================================
______________________ ERROR collecting test_mplogging.py ______________________
File "/home/jonathan/UC/Git Repositories/isiiwesuu/Dictionary/tests/petaapan/logging/test_mplogging.py", line 11
in <module>
> import petaapan.logging.mplogging as ml
File "/home/jonathan/UC/Git Repositories/isiiwesuu/Dictionary/tests/petaapan/logging/<frozen importlib._bootstrap>", line 1564
in _find_and_load
> ???
File "/home/jonathan/UC/Git Repositories/isiiwesuu/Dictionary/tests/petaapan/logging/<frozen importlib._bootstrap>", line 1522
in _find_and_load_unlocked
> ???
File "/home/jonathan/UC/Git Repositories/isiiwesuu/Dictionary/tests/petaapan/logging/<frozen importlib._bootstrap>", line 1476
in _find_module
> ???
File "/home/jonathan/isiiwesuu/lib/python3.3/site-packages/_pytest/assertion/rewrite.py", line 68
in find_module
> fd, fn, desc = imp.find_module(lastname, path)
File "/home/jonathan/isiiwesuu/lib/python3.3/imp.py", line 197
in find_module
> "not {}".format(type(name)))
E RuntimeError: 'list' must be None or a list, not <class 'str'>
=========================== 1 error in 0.49 seconds ============================
Here is test_mplogging.py
relevant parts:
import logging
from os import getcwd
from multiprocessing import Queue, Process
import petaapan.logging.mplogging as ml
Can anyone suggest what I need to do in this situation?
As I can see you have petaapan.logging.mplogging
under Dictionary/src
, but not under Dictionary/test
.
I believe the interpreter parses petaapan
from the import
instruction and finds it out in Dictionary/test
and then suggests that it is the module you refer to. But after that it cannot find mplogging
in Dictionary/test/petaapan/logging
(in the scope of detected module) and thus throws an exception.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With