Skip to content

Commit

Permalink
Split app fixture into function and fixture
Browse files Browse the repository at this point in the history
Using a fixture as a function is deprecated in pytest 3.7.0 and will be
an error in pytest 4
  • Loading branch information
lfdebrux committed Sep 21, 2018
1 parent aa89296 commit 626156a
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,19 @@ def log_to_null():
yield


@pytest.fixture
def app(request):
def create_app(request):
app = Flask(__name__)
app.root_path = request.fspath.dirname
init_app(app)
app.config['SECRET_KEY'] = 'secret_key'
return app


@pytest.fixture
def app(request):
return create_app(request)


@pytest.fixture
def app_with_stream_logger(request):
"""Force StreamHandler to use our StringIO object.
Expand All @@ -44,7 +48,7 @@ def app_with_stream_logger(request):
stream = StringIO()
with mock.patch('dmutils.logging.logging.StreamHandler', return_value=StreamHandler(stream)):
# Use the above app fixture method to return the app and return our stream
yield app(request), stream
yield create_app(request), stream


@pytest.fixture
Expand All @@ -53,7 +57,7 @@ def app_with_mocked_logger(request):
"""
with mock.patch('flask.app.create_logger', return_value=mock.Mock(spec=Logger('flask.app'), handlers=[])):
# Use the above app fixture method to return the app
yield app(request)
yield create_app(request)


@pytest.yield_fixture
Expand Down

0 comments on commit 626156a

Please sign in to comment.