reset bp method for test-scoped app fixtures
This commit is contained in:
parent
00be8d24ac
commit
6ea01cb9a9
2 changed files with 37 additions and 0 deletions
|
|
@ -469,6 +469,13 @@ class Blueprint(Scaffold):
|
||||||
bp_options["name_prefix"] = name
|
bp_options["name_prefix"] = name
|
||||||
blueprint.register(app, bp_options)
|
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
|
@setupmethod
|
||||||
def add_url_rule(
|
def add_url_rule(
|
||||||
self,
|
self,
|
||||||
|
|
|
||||||
30
tests/test_nested_blueprints.py
Normal file
30
tests/test_nested_blueprints.py
Normal 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
|
||||||
Loading…
Add table
Add a link
Reference in a new issue