如何从基础导入多个级别的模块?

问题描述 投票:0回答:1

我试图从pytest运行目录中调用几个级别的模块。如何导入此模块?

我试过了:

sys.path.insert(0, 'path/to/module')
import modulename

这是目录结构:

tools
  common
    modulename.py (contains class A)
  functional_test (this is where I'm running pytest; tools/functional_test)
    conftest.py
    pytest.ini
    tests
      typea (this is tools/funtional_tests/tests/typea)
        tests_typea1.py

Under tests_typea1.py, I want to import class A from modulename.py under tools/common.

获得以下错误:

ImportError
ModuleNotFoundError: No module named 'modulename'
pytest
1个回答
0
投票

好吧,在让另一个人查看我的代码之后,我意识到我错过了拼写我的导入。呃......自我注意:改变字体样式并确认拼写。 :)。以上sys.path.insertsys.path.appendimport <modulename>工作。

© www.soinside.com 2019 - 2024. All rights reserved.