You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

单元测试导入app模块时触发ModuleNotFoundError问题求助

单元测试导入app模块时触发ModuleNotFoundError问题求助

大家好,我遇到了一个Python单元测试的导入问题,想请各位帮忙排查下。

我的项目根目录是poker_bot_final,单元测试文件的路径为:poker_bot_final/test_suite/test_app.py

在这个测试文件的顶部,我写了这样的导入语句:

from app import (are_check_raise_conditions_met, go_to_the_right_street, run_this_on_pre_flop_app_dot_py,
                 fill_my_hand_rating_on_flop_turn_river, run_new_hand, analyse_current_street,
                 calculate_no_players_to_act, am_i_in_position_to_bettor_calculator, my_SPR_calculator)

但运行测试时,我收到了如下报错信息:

ImportError while importing test module '/Users/patrickchong/Desktop/poker_bot_final/test_suite/test_app.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
../../miniconda3/envs/plo/lib/python3.10/importlib/__init__.py:126: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
test_suite/test_app.py:3: in <module>
    from app import (are_check_raise_conditions_met, go_to_the_right_street, run_this_on_pre_flop_app_dot_py,
E   ModuleNotFoundError: No module named 'app'

补充说明:我所有的Python目录里都已经添加了__init__.py文件,但还是出现了找不到app模块的问题,请问该怎么解决呢?

备注:内容来源于stack exchange,提问作者kahhengchong

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.14 17:12:58