无法 运行 覆盖 pytest-cov 和 pytest
Not able to run the coverage with pytest-cov and pytest
面对 运行 具有覆盖率的 pytest 中的问题,我已经完成了 SO posts 但无法解决这个问题,我相信我在这里遗漏了一些东西..
在用户是我项目的应用程序时出现以下错误
ModuleNotFoundError: No module named 'users'
django.core.exceptions.ImproperlyConfigured: Requested setting INSTALLED_APPS, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.
我的pytest.ini文件内容
[pytest] DJANGO_SETTINGS_MODULE = cloudstack.settings
python_files = tests.py test_*.py *_test.py
addopts = -v --ignore=venv --cov=. --cov-report=html
我也尝试过添加 DJANGO_SETTINGS_MODULE 作为环境变量然后我收到不同的错误提示 cloudstack module is not found
.
我在执行这些测试时处于激活环境中。
编辑
我查看了堆栈溢出的每个 post 以修复 运行 中的错误,覆盖 none 的 pytest 帮助我解决了这个问题。
PATH issue with pytest 'ImportError: No module named YadaYadaYada'
ImproperlyConfigured: You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings
并且我按照 SO posts'
中的说明对齐了所有内容
$ type -a coverage coverage is
/cygdrive/c/#Work#/Python/Django/Projects/cloudstacko/cvenv/bin/coverage
$ type -a pytest pytest is
/cygdrive/c/#Work#/Python/Django/Projects/cloudstacko/cvenv/bin/pytest
$ type -a python python is
/cygdrive/c/#Work#/Python/Django/Projects/cloudstacko/cvenv/bin/python
sys.path
['/cygdrive/c/#Work#/Python/Django/Projects/cloudstacko/cloudstacko', '/usr/lib/python36.zip', '/usr/lib/python3.6', '/usr/lib/python3.6/lib-dynload', '/cygdrive/c/#Work#/Python/Django/Projects/cloudstacko/cvenv/lib/python3.6/site-packages']
拯救我一天的图书馆。
$ pip install pytest-django
面对 运行 具有覆盖率的 pytest 中的问题,我已经完成了 SO posts 但无法解决这个问题,我相信我在这里遗漏了一些东西..
在用户是我项目的应用程序时出现以下错误
ModuleNotFoundError: No module named 'users'
django.core.exceptions.ImproperlyConfigured: Requested setting INSTALLED_APPS, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.
我的pytest.ini文件内容
[pytest] DJANGO_SETTINGS_MODULE = cloudstack.settings
python_files = tests.py test_*.py *_test.py
addopts = -v --ignore=venv --cov=. --cov-report=html
我也尝试过添加 DJANGO_SETTINGS_MODULE 作为环境变量然后我收到不同的错误提示 cloudstack module is not found
.
我在执行这些测试时处于激活环境中。
编辑 我查看了堆栈溢出的每个 post 以修复 运行 中的错误,覆盖 none 的 pytest 帮助我解决了这个问题。
PATH issue with pytest 'ImportError: No module named YadaYadaYada'
ImproperlyConfigured: You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings
并且我按照 SO posts'
中的说明对齐了所有内容$ type -a coverage coverage is /cygdrive/c/#Work#/Python/Django/Projects/cloudstacko/cvenv/bin/coverage
$ type -a pytest pytest is /cygdrive/c/#Work#/Python/Django/Projects/cloudstacko/cvenv/bin/pytest
$ type -a python python is /cygdrive/c/#Work#/Python/Django/Projects/cloudstacko/cvenv/bin/python
sys.path ['/cygdrive/c/#Work#/Python/Django/Projects/cloudstacko/cloudstacko', '/usr/lib/python36.zip', '/usr/lib/python3.6', '/usr/lib/python3.6/lib-dynload', '/cygdrive/c/#Work#/Python/Django/Projects/cloudstacko/cvenv/lib/python3.6/site-packages']
拯救我一天的图书馆。
$ pip install pytest-django