pytest-dev / pytest-dev/pytest
`pytest --debug` badly interacts with `flask.current_app` on pytest 6.2.4
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 14.5k
- Forks
- 3.4k
- Avg merge
- 2d 9h
- Merged PRs (30d)
- 35
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the minimal Flask fixture with pytest --debug and --collect-only, then inspect the pytest tracing path implicated in the traceback, especially pluggy/_tracing.py. Done means importing flask.current_app no longer triggers an application-context error during collection, with a regression test covering the reported command.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- flask, python
- Domain
- backend, testing-qa
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100