diff --git a/src/flask/blueprints.py b/src/flask/blueprints.py index 104f8acf..d1afa8e8 100644 --- a/src/flask/blueprints.py +++ b/src/flask/blueprints.py @@ -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, diff --git a/tests/test_nested_blueprints.py b/tests/test_nested_blueprints.py new file mode 100644 index 00000000..79db8dc0 --- /dev/null +++ b/tests/test_nested_blueprints.py @@ -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