我正在尝试设置 pytest 并且模块名称未被识别

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

我第一次尝试配置

pytest

当我运行命令时:

python -m pytest

我收到以下错误:


ImportError: No module named 'Socialmedia.settings.local'; 'Socialmedia.settings' is not a package

pytest-django found a Django project in C:\Users\Alon\PycharmProjects\Socialmedia (it contains manage.py) and added it to the Python path.
If this is wrong, add "django_find_project = false" to pytest.ini and explicitly manage your Python path.

py测试文件:

[pytest]
DJANGO_SETTINGS_MODULE = Socialmedia.settings.local
python_files = test_*.py

看起来错误是由于

socialmedia
未被识别而导致的。

我尝试过:

更改 init 文件并在其中添加模块。

import Socialmedia
from Socialmedia import settings
__all__ = [Socialmedia, settings]

从项目移动到应用程序的另一个目录。

知道如何使

socialmedia
在此文件中可访问吗?

python django path pytest pytest-django
1个回答
0
投票

试试这个:

py -m pip install pytest

或:

python -m pip install pytest

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