擅长:python、mysql、java
<p>当我在使用<code>pytest</code>时遇到类似的问题时,我遵循了@brenns10的答案。</p>
<p>我遵循了将其放入测试设置的建议,这是有效的:</p>
<pre><code>import pytest
from src.app import app
@pytest.fixture
def app_context():
with app.app_context():
yield
def some_test(app_context):
<test code that needs the app context>
</code></pre>