无法在我的测试文件中导入我自己的模块

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

我有以下项目结构:

.
├── README.md
├── document_processing
│   ├── Config.py
│   ├── DocumentParser.py
│   ├── FileChecker.py
│   └── __init__.py
├── indexing.py
└── tests
    ├── CheckFileTest.py
    └── __init__.py

在CheckFileTest.py中,我对FileChecker.py函数实现了一些测试。

import unittest
from document_processing.Config import Config
from document_processing.FileChecker import FileChecker

class CheckFileTest(unittest.TestCase):
    def __init__(self):
        self.config = Config()
        self.fc = FileChecker(self.config)
    
    def test_not_empty_line(self):
        ...
        
    def test_line_format(self):
        ...
        
if __name__ == "__main__":
    unittest.main()

不幸的是,当我尝试运行测试文件(从项目根目录启动)时遇到此错误:

Traceback (most recent call last):
  File "/Users/thomaslaurent/Dev/MIRCV_project/tests/CheckFileTest.py", line 3, in <module>
    from document_processing.Config import Config
ModuleNotFoundError: No module named 'document_processing

我见过很多关于这方面的东西,但我无法弄清楚这个结构阻止了什么。

python python-3.x python-module python-packaging
1个回答
0
投票
from ..document_processing.Config import Config
from ..document_processing.FileChecker import FileChecker
© www.soinside.com 2019 - 2024. All rights reserved.