我有一個測試需要關於如何運行的說明。超出工作範圍的目標是防範,指導手冊應該包含一個運行文件的命令,一個運行測試。我的朋友說運行單元測試將不需要的文件是在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()
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
沒有骰子
它位於ordoro_test文件夾中,與其他2個文件相同級別 – codyc4321
@ codyc4321在ordoro_test文件夾的一個級別中添加一個,而不是它 –