为了账号安全,请及时绑定邮箱和手机立即绑定

pytest的文件夹结构和导入问题

pytest的文件夹结构和导入问题

慕容3067478 2021-07-09 14:11:29
想象一个简单的文件夹结构:my_folder/    __init__.py    funcs.py    tests/        test_funcs.py函数.py:def f():    return 2__init__.py:from funcs import ftest_funcs.py:from funcs import fdef test_f():    assert f() == 2这是文档中建议的方法之一:https : //pytest.readthedocs.io/en/reorganize-docs/new-docs/user/directory_structure.html但是当我从my_folder以下位置运行 pytest 时:tests/test_funcs.py:1: in <module>    from funcs import fE   ModuleNotFoundError: No module named 'funcs'这很奇怪,因为我会认为它pytest设置了它运行的路径,所以如果不手动处理它就不会出现这些类型的错误。文档也没有给出任何关于这一点的迹象......他们只是说:通常,您可以通过指向测试目录或模块来运行测试:pytest tests/test_appmodule.py      # for external test dirspytest src/tests/test_appmodule.py  # for inlined test dirspytest src                          # run tests in all below test directoriespytest                              # run all tests below current dir我错过了什么?
查看完整描述

2 回答

  • 2 回答
  • 0 关注
  • 282 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号