2016-03-06 38 views
0

我有一个测试需要关于如何运行的说明。超出工作范围的目标是防范,指导手册应该包含一个运行文件的命令,一个运行测试。我的朋友说运行单元测试将不需要的文件是在PYTHONPATH,因为它首先检查当前目录,但我得到:ImportError:没有名为mymodule.main的模块

import unittest 

from ordoro_test.main import OrdoroETLMachine 

class ETLMachineTests(unittest.TestCase): 

    def setUp(self): 
     self.api_url = 'https://9g9xhayrh5.execute-api.us-west-2.amazonaws.com/test/data' 
     self.headers = {'accept': 'application/json'} 

    def test_data_is_returned(self): 
     print(OrdoroETLMachine.get_email_data()) 



if __name__ == '__main__': 
    unittest.main() 

enter image description here

cchilders:~/ordoro_test [master]$ python test.py 
Traceback (most recent call last): 
    File "test.py", line 4, in <module> 
    from ordoro_test.main import OrdoroETLMachine 
ImportError: No module named ordoro_test.main 
cchilders:~/ordoro_test [master]$ ls -l 
total 8 
-rw-rw-r-- 1 cchilders cchilders 0 Mar 5 19:15 __init__.py 
-rwxr-xr-x 1 cchilders cchilders 3099 Mar 5 20:12 main.py 
-rwxr-xr-x 1 cchilders cchilders 441 Mar 5 20:19 test.py 

如何解决,并允许进口的最简单的方法可能?谢谢

我尝试

from ordoro_test.assignment.main import OrdoroETLMachine 

enter image description here

没有骰子

回答

0

添加空__init__.py文件中的一个水平ordoro_test文件夹应解决您的问题。

有关更多信息,请参阅Python 2.7, Modules section

+0

它位于ordoro_test文件夹中,与其他2个文件相同级别 – codyc4321

+0

@ codyc4321在ordoro_test文件夹的一个级别中添加一个,而不是它 –

相关问题