reset bp method for test-scoped app fixtures

This commit is contained in:
Rasim Andiran 2022-09-07 21:31:43 +03:00
parent 00be8d24ac
commit 6ea01cb9a9
2 changed files with 37 additions and 0 deletions

View file

@ -469,6 +469,13 @@ class Blueprint(Scaffold):
bp_options["name_prefix"] = name
blueprint.register(app, bp_options)
def reset_blueprint(self):
"""Resets this blueprint. Clears registered child blueprints and
set _got_registered_once flag to False
"""
self._blueprints = []
self._got_registered_once = False
@setupmethod
def add_url_rule(
self,

View file

@ -0,0 +1,30 @@
import pytest
from flask import Blueprint
from flask import Flask
parent = Blueprint("parent", __name__)
child = Blueprint("child", __name__)
def create_app():
app = Flask(__name__)
parent.register_blueprint(child, url_prefix="/child")
app.register_blueprint(parent, url_prefix="/parent")
return app
@pytest.fixture
def app():
app = create_app()
yield app
parent.reset_blueprint()
def test_1(app):
pass
def test_2(app):
pass