-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Open
Labels
topic: collectionrelated to the collection phaserelated to the collection phasetype: bugproblem that needs to be addressedproblem that needs to be addressed
Description
With a minimal Flask 1.1.4 "app" set up in a fixture, flask.current_app gets broken when pytest --debug is used.
from flask import Flask
from flask import current_app
import pytest
@pytest.fixture
def myapp():
return Flask("boom")
def test_app(myapp):
current_app
The above example succeeds when I run pytest-3 in it:
$ pytest-3
========== test session starts ==========
platform linux -- Python 3.8.5, pytest-4.6.9, py-1.8.1, pluggy-0.13.0
rootdir: /home/danilo/hotjar/tmp/fd
collected 1 item
test_app.py . [100%]
========== 1 passed in 0.09 seconds ==========
However, passing --debug makes it fail during collection (even with --collect-only too):
$ pytest-3 --debug
writing pytestdebug information to /home/danilo/tmp/fd/pytestdebug.log
=========================================================================================== test session starts ============================================================================================
platform linux -- Python 3.8.5, pytest-4.6.9, py-1.8.1, pluggy-0.13.0 -- /usr/bin/python3
using: pytest-4.6.9 pylib-1.8.1
rootdir: /home/danilo/tmp/fd
collected 0 items / 1 errors
================================================================================================== ERRORS ==================================================================================================
_______________________________________________________________________________________ ERROR collecting test_app.py _______________________________________________________________________________________
/usr/lib/python3/dist-packages/pluggy/hooks.py:286: in __call__
return self._hookexec(self, self.get_hookimpls(), kwargs)
/usr/lib/python3/dist-packages/pluggy/manager.py:92: in _hookexec
return self._inner_hookexec(hook, methods, kwargs)
/usr/lib/python3/dist-packages/pluggy/manager.py:332: in traced_hookexec
before(hook.name, hook_impls, kwargs)
/usr/lib/python3/dist-packages/pluggy/manager.py:350: in before
hooktrace(hook_name, kwargs)
/usr/lib/python3/dist-packages/pluggy/_tracing.py:59: in __call__
self.root._processmessage(self.tags, args)
/usr/lib/python3/dist-packages/pluggy/_tracing.py:34: in _processmessage
self._writer(self._format_message(tags, args))
/usr/lib/python3/dist-packages/pluggy/_tracing.py:28: in _format_message
lines.append("%s %s: %s\n" % (indent, name, value))
/usr/lib/python3/dist-packages/werkzeug/local.py:367: in <lambda>
__str__ = lambda x: str(x._get_current_object())
/usr/lib/python3/dist-packages/werkzeug/local.py:307: in _get_current_object
return self.__local()
/usr/lib/python3/dist-packages/flask/globals.py:52: in _find_app
raise RuntimeError(_app_ctx_err_msg)
E RuntimeError: Working outside of application context.
E
E This typically means that you attempted to use functionality that needed
E to interface with the current application object in some way. To solve
E this, set up an application context with app.app_context(). See the
E documentation for more information.
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 1 errors during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
========================================================================================= 1 error in 0.15 seconds ==========================================================================================
wrote pytestdebug information to /home/danilo/tmp/fd/pytestdebug.log
Moving flask.current_app import into the test itself makes it pass, so --debug somehow "materializes" the import and it fails with it.
Filing as pytest bug because it works without --debug.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
topic: collectionrelated to the collection phaserelated to the collection phasetype: bugproblem that needs to be addressedproblem that needs to be addressed