python - 将 Python 配置为复杂的 Django 项目
问题描述
我需要在我的 django 应用程序中配置 pytest。但是目录的结构与我习惯的不同。
.
├── apps
│ ├── __pycache__
│ ├── admcore
│ ├── ...
│ ├── cauth
│ ├── webservice
│ └── webshell
├── doc
│ └── ...
├── lib
│ └── ...
├── ...
└── project
├── __init__.py
├── globalsettings.py
├── local
│ ├── __init__.py
│ ├── app.uwsgi
│ ├── manage.py
│ ├── settings.py
│ └── wsgi.py
├── mailconf.py
└── urls.py
我建立pytest.ini
[pytest]
DJANGO_SETTINGS_MODULE=sgp.local.test_settings
addopts = --nomigrations --cov=. --cov-report=html
和test_settings.py
文件
#!/usr/bin/env python
import os
import sys
from project import globalsettings
SECRET_KEY = "12341234AFDQFDQSDFAZR123D"
ROOT_PATH = '/usr/local/sgp'
BASEURL_ROOT = ''
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': ':memory:'
}
}
我把这两个文件放在project
目录中。
.
├── apps
│ ├── __pycache__
│ ├── admcore
│ ├── ...
│ ├── cauth
│ ├── webservice
│ └── webshell
├── doc
│ └── ...
├── lib
│ └── ...
├── ...
└── project
├── __init__.py
├── globalsettings.py
├── local
│ ├── __init__.py
│ ├── app.uwsgi
│ ├── manage.py
│ ├── pytest.ini
│ ├── settings.py
│ ├── test_settings.py
│ └── wsgi.py
├── mailconf.py
└── urls.py
但它并没有像我预期的那样工作。我在 webservice 应用程序中进行了一项测试,但是当我运行pytest
命令时,我得到了:
platform darwin -- Python 3.7.4, pytest-5.2.0, py-1.8.0, pluggy-0.13.0
Django settings: project.local.test_settings (from environment variable)
rootdir: /project/local, inifile: pytest.ini
plugins: django-3.5.1, cov-2.7.1
collected 0 items
---------- coverage: platform darwin, python 3.7.4-final-0 -----------
Coverage HTML written to dir htmlcov
=========================================================================================================== no tests ran in 0.15s ============================================================================================================
我不知道如何为这个项目配置 pytest。
解决方案
推荐阅读
- android - 在android中根据时间对用户数据输入进行排序和管理
- javascript - 使用 python 和 spacy lib 部署 js
- vhdl - vhdl 指令要求:非 64 位模式
- javascript - 在模态中获取图像的 id 并将其插入隐藏的输入中
- sql - SQLite无法选择数据时如何拒绝用户错误
- javascript - 无服务器调用本地什么都不做
- c# - 将数据库中的信息存储在数组中
- java -
通用返回类型 - tensorflow - tflite : tflite 有什么方法可以处理各种形状的输入
- android - 有没有办法在 Xamarin Native android 中禁用 Android 上的选项卡式页面之间的滑动?