Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

request causes doctest to fail #4731

Closed
ftnext opened this issue Aug 3, 2022 · 1 comment
Closed

request causes doctest to fail #4731

ftnext opened this issue Aug 3, 2022 · 1 comment

Comments

@ftnext
Copy link

ftnext commented Aug 3, 2022

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:

  1. Create the following file as example.py
from flask import request


def awesome_function():
    return "spam"
  1. 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.

@davidism
Copy link
Member

davidism commented Aug 3, 2022

Duplicate of pallets/werkzeug#2485. This is a longstanding issue with doctest/inspect and anything else that unconditionally tries to access attributes on global objects.

@davidism davidism closed this as completed Aug 3, 2022
@davidism davidism changed the title from flask import request causes nosetests --with-doctest to fail in Flask 2.2.0 request causes doctest to fail Aug 3, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 18, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants