运行 pytest 时出现 ModuleNotFoundError

时间:2021-07-12 23:27:29

标签: python pytest

我是 Python-Flask 环境的新手。在我的项目中,我有一个 Flask API 项目,我在其中创建了几个单元测试。 API 使用 POSTMAN 或任何 API 客户端按预期工作,但我正在尝试使用“pytest”命令运行单元测试,它在我的单元测试中出现错误,例如“ModuleNotFoundError: No module named

@pytest.fixture(scope='session')
def app():
    """Return a session-wide application configured in TEST mode."""
    _app = create_app()
    return _app
@pytest.fixture(scope='function')
def app_request():
    """Return a session-wide application configured in TEST mode."""
    _app = create_app()
    return _app


@pytest.fixture(scope='session')
def client(app):  # pylint: disable=redefined-outer-name
    """Return a session-wide Flask test client."""
    return app.test_client()

我使用的是 Windows 10、VS Code、Python 3.8.9 和 flask-expects-json==1.5.0、redis==3.5.3。该问题出现在我机器上的所有项目上,即使我试图在不同的项目上隔离问题。

另一点要指出的是,在代码文件上有警告,如“无法解析导入“flask_expects_json”PylancereportMissingImports”。但是在运行时,没有问题。 这里的 pytest 单元测试会出现什么问题?请帮忙。

0 个答案:

没有答案