python - Pytest - 收集了 0 个项目,没有进行测试
问题描述
在根目录中,但无论运行什么命令,pytest 都不会运行测试(py.test、pytest、python3 -m pytest ...)
根据此处的其他帖子,我遵循了所有这些建议:
- 验证所有带有测试用例的文件都以“test_”开头。
- 验证所有测试用例名称是否也以“test_”开头。
- 验证您是否已在根目录中创建了 pytest.ini 文件
- 验证您在项目的所有目录/子目录中是否有init .py 文件
文件目录:
.
├── Procfile
├── __pycache__
├── config.py
├── learning_flashcards
│ ├── __init__.py
│ ├── __pycache__
│ │ ├── __init__.cpython-36.pyc
│ │ ├── app.cpython-36.pyc
│ │ ├── models.cpython-36.pyc
│ │ └── views.cpython-36.pyc
│ ├── app.py
│ ├── db.py
│ ├── models.py
│ ├── static
│ │ └── style.css
│ ├── templates
│ └── views.py
├── learning_flashcards.egg-info
│ ├── PKG-INFO
│ ├── SOURCES.txt
│ ├── dependency_links.txt
│ ├── requires.txt
│ └── top_level.txt
├── manage.py
├── migrations
│ ├── README
│ ├── alembic.ini
│ ├── env.py
│ ├── script.py.mako
│ └── versions
├── pytest.ini
├── requirements
│ ├── common.txt
│ ├── dev.txt
│ └── runtime.txt
├── requirements.txt
├── setup.py
├── tests
│ ├── [pytest]
│ ├── __init__.py
│ ├── __pycache__
│ │ ├── __init__.cpython-36.pyc
│ │ ├── conftest.cpython-36-pytest-5.4.3.pyc
│ │ ├── test_data.cpython-36-pytest-5.4.3.pyc
│ │ └── test_site.cpython-36-pytest-5.4.3.pyc
│ ├── conftest.py
│ ├── test_data.py
│ └── test_site.py
└── venv
测试文件 test_site.py:
import pytest
from learning_flashcards.app import create_app
@pytest.fixture(autouse=True)
def test_site(app):
assert app.get(url_for('/')).status_code == 200
竞赛.py:
import pytest
from learning_flashcards.app import create_app
@pytest.fixture
def app():
app = create_app()
return app
pytest.ini:
[pytest]
minversion = 5.4.3
testpath = tests
以前从未使用过 pytest,所以这可能是我的方法有问题。
解决方案
推荐阅读
- coldfusion - CFLDAP 名称属性...不能使用结构?
- android - Google 控制台 APK 上传 - 新应用程序失败
- jquery - 如何为数组中的元素获取与这些输入标签关联的文本
- google-cloud-platform - 使用我自己的 SSL 证书和 Google Cloud Run(完全托管)进行 SSL 固定
- python - 使用 selenium 和 python 将具有相同类的所有元素添加到列表中
- entity-framework-core - 在 EF Core 3.1 中调用一个简单的存储过程
- python-3.x - Flask Pdfkit-无法添加自定义字体
- ios - 如何以编程方式向下滚动推送通知打开的视图?
- sql - 如何计算具有不同包含表字段的两个不同表的总和
- linux - 使 nautilus 在挂载磁盘时停止询问密码