小编vtb*_*ose的帖子

运行简单的 pytest 时出现 ModuleNotFoundError

Python 版本 3.6

\n

我有以下文件夹结构

\n
.\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 main.py\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 tests/\n|     \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 test_Car.py\n\xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 automobiles/\n      \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 Car.py\n
Run Code Online (Sandbox Code Playgroud)\n

我的程序.py

\n
from automobiles.Car import Car\n\np = Car("Grey Sedan")\nprint(p.descriptive_name())\n
Run Code Online (Sandbox Code Playgroud)\n

卡比

\n
class Car():\n    description = "Default"\n    \n    def __init__(self, message):\n        self.description = message\n\n    def descriptive_name(self):\n        return self.description\n
Run Code Online (Sandbox Code Playgroud)\n

test_Car.py

\n
from automobiles.Car import Car\n\ndef test_descriptive_name():\n    input_string = "Blue Hatchback"\n    p = Car(input_string)\n    assert(p.descriptive_name() == input_string)\n
Run Code Online (Sandbox Code Playgroud)\n

运行pytest时时,出现以下错误-

\n
Traceback:\n..\\..\\..\\AppData\\Local\\Programs\\Python\\Python36\\lib\\importlib\\__init__.py:126: in import_module\n    return _bootstrap._gcd_import(name[level:], package, level)\ntests\\test_Car.py:2: in <module>\n    from automobiles.Car import Car\nE   ModuleNotFoundError: …
Run Code Online (Sandbox Code Playgroud)

python pytest

4
推荐指数
1
解决办法
3058
查看次数

标签 统计

pytest ×1

python ×1