我有一个简单的python项目。其结构如下:
C:\projects\python\Testovnik>tree
Folder PATH listing
Volume serial number is BC5F-5E5E
C:.
ââââ.vscode
â ââââ.ropeproject
ââââTestovnik
â ââââlib
â â ââââ__pycache__
â ââââquestions
ââââtests
现在在
tests
目录我有这个文件:
question_tests.py
import unittest
from Testovnik.lib.question import Question
from Testovnik.lib.question_file import QuestionFile
test_file = '..\\questions\\002.txt'
class TestQuestion(unittest.TestCase):
def test_question(self):
question_file = QuestionFile(test_file)
self.assertEqual(question_file.get_question, 'Pisior?')
def test_answers_length(self):
question_file = QuestionFile(test_file)
self.assertEqual(len(question_file.get_answers()), 4)
if __name__ == '__main__':
unittest.main()
我想导入两个类:
Question
和
QuestionFile
两者相应地位于:
Testovnik\lib\question.py
和
Testovnik\lib\question_file.py
当我跑步时
python question_tests.py
这让我想到:
C:\projects\python\Testovnik\tests>python question_tests.py
Traceback (most recent call last):
File "question_tests.py", line 3, in <module>
from Testovnik.lib.question import Question
ModuleNotFoundError: No module named 'Testovnik
我的问题是,我应该采取什么样的方式使其发挥作用?
@编辑这是我的项目结构和所有文件(
__init__.py
文件为空):