首页 > 解决方案 > Pytest - 收集了 0 个项目,没有进行测试

问题描述

在根目录中,但无论运行什么命令,pytest 都不会运行测试(py.test、pytest、python3 -m pytest ...)

根据此处的其他帖子,我遵循了所有这些建议:

文件目录:

.
├── 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,所以这可能是我的方法有问题。

标签: pythonflaskpytest

解决方案


推荐阅读