→ uranusjr: 一般會把測試和你的主要程式平行放, 你的例子應該是和 03/20 17:28
→ uranusjr: bot 同一層; 不知道你怎麼執行 unit test, 但通常會寫成 03/20 17:29
→ uranusjr: import bot.weatherParser.weather 03/20 17:30
→ zerof: from bot import ... ,在 bot/ 執行 03/20 18:22
→ rebellionyu: 我剛剛測試了一下,放在tests/unit/test.py, 03/20 18:34
→ rebellionyu: 要用python -m unittest tests.unit.test 跑 03/20 18:35
→ rebellionyu: 而test.py只要from weatherParser import weather 03/20 18:35
→ rebellionyu: 但如果直接跑 python ./tests/unit/test.py 就不行 03/20 18:36
→ rebellionyu: 會說找不到weatherParser這個module 03/20 18:36
→ s860134: 你資料夾每一層都要有 __init__.py 03/21 23:14
→ s860134: import 搜尋是看 sys.path,根據你執行方式會改變 03/21 23:32
→ s860134: python ./tests/unit/test.py 他 sys.path 就會在 \unit 03/21 23:33
→ rebellionyu: 我後來的測試,bot資料夾裡面長這樣 03/23 14:46
→ rebellionyu: 我在bot資料夾裡,python tests/unit/test_weather_ 03/23 14:47
→ rebellionyu: parser.py,而此py檔from ...weather_parser import 03/23 14:48
→ rebellionyu: 會出現此error ValueError: attempted relative 03/23 14:49
→ rebellionyu: import beyond top-level package 03/23 14:49
→ rebellionyu: 照理說我的sys.path應該是 /unit,那我用...weather_ 03/23 14:49
→ rebellionyu: parser應該要可以才是… 03/23 14:50
→ zerof: 執行 python 的 path 才會是 pwd 03/23 21:39