Issue 1:
Congrats on the release of Flask 2.2.0🎉

I noticed some weird behavior.

Environment:

Python version: 3.8.6

Flask version: 2.2.0

nose 1.3.7

Procedure:

Create the following file as example.py

from flask import request

def awesome_function():
return "spam"

Run nosetests with doctests

$ nosetests --with-doctest -v

AS IS: nosetests fail

Failure: RuntimeError (Working outside of request context.

This typically means that you attempted to use functionality that needed
an active HTTP request. Consult the documentation on testing for
information about how to avoid this problem.) ... ERROR

======================================================================
ERROR: Failure: RuntimeError (Working outside of request context.

This typically means that you attempted to use functionality that needed
an active HTTP request. Consult the documentation on testing for
information about how to avoid this problem.)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Users/.../venv/lib/python3.8/site-packages/nose/failure.py", line 39, in runTest
raise self.exc_val.with_traceback(self.tb)
File "/Users/.../venv/lib/python3.8/site-packages/nose/plugins/manager.py", line 154, in generate
for r in result:
File "/Users/.../venv/lib/python3.8/site-packages/nose/plugins/doctests.py", line 228, in loadTestsFromModule
tests = self.finder.find(module)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/doctest.py", line 939, in find
self._find(tests, obj, name, module, source_lines, globs, {})
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/doctest.py", line 998, in _find
if ((inspect.isroutine(inspect.unwrap(val))
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/inspect.py", line 520, in unwrap
while _is_wrapper(func):
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/inspect.py", line 511, in _is_wrapper
return hasattr(f, '__wrapped__')
File "/Users/.../venv/lib/python3.8/site-packages/werkzeug/local.py", line 316, in __get__
obj = instance._get_current_object() # type: ignore[misc]
File "/Users/.../venv/lib/python3.8/site-packages/werkzeug/local.py", line 509, in _get_current_object
raise RuntimeError(unbound_message) from None
RuntimeError: Working outside of request context.

This typically means that you attempted to use functionality that needed
an active HTTP request. Consult the documentation on testing for
information about how to avoid this problem.

----------------------------------------------------------------------
Ran 1 test in 0.107s

FAILED (errors=1)

TO BE: nosetests do NOT fail (0 tests run)

In procedure 1, implementing some doctests do not change the result.

Workaround: pip install -U 'flask<2.2' (installed flask 2.1.3)

$ nosetests --with-doctest -v

----------------------------------------------------------------------
Ran 0 tests in 0.096s

OK

Flask 2.1.3 does not raise the error.

Is this a bug embedded in the upgrade to 2.2.0?

I was wondering if it would be better to write it in the nose repository,

but I think from frask import request is the cause, so I'll share it here.

Issue 2:
Migrating from Flask 2.1 to 2.2 failed a few unit tests of mine. It looks like we can no longer import flask.request top level in a test file (reproduced across Python 3.7, 3.8, 3.9, 3.10):

from flask import Flask
from flask import request

def test_something():
assert True

This gives a RuntimeError:

E RuntimeError: Working outside of request context.
E
E This typically means that you attempted to use functionality that needed
E an active HTTP request. Consult the documentation on testing for
E information about how to avoid this problem.

On my side the fix was simple: importing flask.request outside of the global scope, just when I actually need it (my actual tests create small Flask apps to test a client).

Edit: forgot to mention that this only occurs when pytest is run with --doctest-modules