Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python ModuleNotFoundError:没有名为';app&x27;在Windows虚拟环境中尝试使用Pytest和Flask创建测试时_Python_Windows_Flask - Fatal编程技术网

Python ModuleNotFoundError:没有名为';app&x27;在Windows虚拟环境中尝试使用Pytest和Flask创建测试时

Python ModuleNotFoundError:没有名为';app&x27;在Windows虚拟环境中尝试使用Pytest和Flask创建测试时,python,windows,flask,Python,Windows,Flask,我正在尝试使用为我的Flask应用程序创建测试,但当我使用pytest运行测试时,它抛出以下错误: Hint: make sure your test modules/packages have valid Python names. Traceback: test\test_flask.py:6: in <module> from app import app E ModuleNotFoundError: No module named 'app' 和init.py:

我正在尝试使用为我的Flask应用程序创建测试,但当我使用pytest运行测试时,它抛出以下错误:

Hint: make sure your test modules/packages have valid Python names.
Traceback:
test\test_flask.py:6: in <module>
    from app import app
E   ModuleNotFoundError: No module named 'app'
init.py:

from flask import Flask, request, jsonify
from config import Config
from flask_sqlalchemy import SQLAlchemy
from flask_migrate import Migrate
from werkzeug.security import generate_password_hash, check_password_hash
from flask_jwt_extended import (
    JWTManager, jwt_required, create_access_token,
    get_jwt_identity
)
from flask_cors import CORS

app = Flask(__name__)
app.config.from_object(Config)
db = SQLAlchemy(app)
migrate = Migrate(app, db)
jwt = JWTManager(app)
CORS(app)
app.config['CORS_HEADERS'] = 'Content-Type'


from app import routes, models
mymanhualist.py:

from app import app

我已经解决了在项目的根目录中创建setup.py并构建我的包的问题,以便测试目录可以访问应用程序包

setup.py:

import setuptools

with open("README.md", "r") as fh:
    long_description = fh.read()

setuptools.setup(
    name="appPackage-YourUser", 
    version="0.0.1",
    author="Your Name",
    author_email="yourownemail@email.com",
    description="",
    long_description=long_description,
    long_description_content_type="text/markdown",
    url="https://github.com/luturol/MyManhuaListAPI",
    packages=setuptools.find_packages(),
    classifiers=[
        "Programming Language :: Python :: 3",
        "License :: OSI Approved :: MIT License",
        "Operating System :: OS Independent",
    ],
    python_requires='>=3.6',
)
刚跑完后:

pip install -e .
这个链接帮助我解决了这个问题

pip install -e .