WDscholia / scholia

Wikidata-based scholarly profiles
https://scholia.toolforge.org
Other
222 stars 79 forks source link

Tox testing errs with "RuntimeError: Working outside of application context #2076

Closed Daniel-Mietchen closed 2 years ago

Daniel-Mietchen commented 2 years ago

Describe the bug

Running tox gives errors

To Reproduce Steps to reproduce the behavior:

pip install tox
tox

Here is what that gave me just now for the main branch:

$ tox
GLOB sdist-make: /workspace/scholia/setup.py
flake8 create: /workspace/scholia/.tox/flake8
flake8 installdeps: flake8, flake8-docstrings
flake8 inst: /workspace/scholia/.tox/.tmp/package/1/scholia-0.3+379.gf236568.zip
flake8 installed: certifi==2022.6.15,charset-normalizer==2.1.0,click==8.1.3,docopt==0.6.2,dominate==2.7.0,feedparser==6.0.10,flake8==5.0.4,flake8-docstrings==1.6.0,Flask==2.2.1,Flask-Bootstrap==3.3.7.1,idna==3.3,importlib-metadata==4.12.0,itsdangerous==2.1.2,Jinja2==3.1.2,lxml==4.9.1,MarkupSafe==2.1.1,mccabe==0.7.0,pycodestyle==2.9.1,pydocstyle==6.1.1,pyflakes==2.5.0,python-dateutil==2.8.2,requests==2.28.1,scholia @ file:///workspace/scholia/.tox/.tmp/package/1/scholia-0.3%2B379.gf236568.zip,sgmllib3k==1.0.0,simplejson==3.17.6,six==1.16.0,snowballstemmer==2.2.0,urllib3==1.26.11,visitor==0.1.3,Werkzeug==2.2.1,zipp==3.8.1
flake8 run-test-pre: PYTHONHASHSEED='2712527208'
flake8 run-test: commands[0] | flake8 scholia
scholia/app/views.py:1924:80: E501 line too long (82 > 79 characters)
scholia/app/views.py:1962:80: E501 line too long (82 > 79 characters)
scholia/app/views.py:1980:80: E501 line too long (82 > 79 characters)
ERROR: InvocationError for command /workspace/scholia/.tox/flake8/bin/flake8 scholia (exited with code 1)
pydocstyle create: /workspace/scholia/.tox/pydocstyle
pydocstyle installdeps: pydocstyle
pydocstyle inst: /workspace/scholia/.tox/.tmp/package/1/scholia-0.3+379.gf236568.zip
pydocstyle installed: certifi==2022.6.15,charset-normalizer==2.1.0,click==8.1.3,docopt==0.6.2,dominate==2.7.0,feedparser==6.0.10,Flask==2.2.1,Flask-Bootstrap==3.3.7.1,idna==3.3,importlib-metadata==4.12.0,itsdangerous==2.1.2,Jinja2==3.1.2,lxml==4.9.1,MarkupSafe==2.1.1,pydocstyle==6.1.1,python-dateutil==2.8.2,requests==2.28.1,scholia @ file:///workspace/scholia/.tox/.tmp/package/1/scholia-0.3%2B379.gf236568.zip,sgmllib3k==1.0.0,simplejson==3.17.6,six==1.16.0,snowballstemmer==2.2.0,urllib3==1.26.11,visitor==0.1.3,Werkzeug==2.2.1,zipp==3.8.1
pydocstyle run-test-pre: PYTHONHASHSEED='2712527208'
pydocstyle run-test: commands[0] | pydocstyle --convention=numpy scholia
py37 create: /workspace/scholia/.tox/py37
ERROR: InterpreterNotFound: python3.7
py38 create: /workspace/scholia/.tox/py38
py38 installdeps: pytest, -rrequirements.txt
py38 inst: /workspace/scholia/.tox/.tmp/package/1/scholia-0.3+379.gf236568.zip
py38 installed: attrs==22.1.0,certifi==2022.6.15,charset-normalizer==2.1.0,click==8.1.3,docopt==0.6.2,dominate==2.7.0,feedparser==6.0.10,Flask==2.2.1,Flask-Bootstrap==3.3.7.1,idna==3.3,importlib-metadata==4.12.0,iniconfig==1.1.1,itsdangerous==2.1.2,Jinja2==3.1.2,lxml==4.9.1,MarkupSafe==2.1.1,packaging==21.3,pluggy==1.0.0,py==1.11.0,pyparsing==3.0.9,pytest==7.1.2,python-dateutil==2.8.2,requests==2.28.1,scholia @ file:///workspace/scholia/.tox/.tmp/package/1/scholia-0.3%2B379.gf236568.zip,sgmllib3k==1.0.0,simplejson==3.17.6,six==1.16.0,tomli==2.0.1,urllib3==1.26.11,visitor==0.1.3,Werkzeug==2.2.1,zipp==3.8.1
py38 run-test-pre: PYTHONHASHSEED='2712527208'
py38 run-test: commands[0] | python -m pytest --doctest-modules scholia
============================================================================= test session starts ==============================================================================
platform linux -- Python 3.8.13, pytest-7.1.2, pluggy-1.0.0
cachedir: .tox/py38/.pytest_cache
rootdir: /workspace/scholia
collected 63 items / 1 error                                                                                                                                                   

==================================================================================== ERRORS ====================================================================================
____________________________________________________________________ ERROR collecting scholia/app/views.py _____________________________________________________________________
/home/gitpod/.pyenv/versions/3.8.13/lib/python3.8/doctest.py:939: in find
    self._find(tests, obj, name, module, source_lines, globs, {})
.tox/py38/lib/python3.8/site-packages/_pytest/doctest.py:533: in _find
    super()._find(  # type:ignore[misc]
/home/gitpod/.pyenv/versions/3.8.13/lib/python3.8/doctest.py:998: in _find
    if ((inspect.isroutine(inspect.unwrap(val))
.tox/py38/lib/python3.8/site-packages/_pytest/doctest.py:475: in _mock_aware_unwrap
    return real_unwrap(func, stop=_is_mocked)
/home/gitpod/.pyenv/versions/3.8.13/lib/python3.8/inspect.py:520: in unwrap
    while _is_wrapper(func):
/home/gitpod/.pyenv/versions/3.8.13/lib/python3.8/inspect.py:514: in _is_wrapper
    return hasattr(f, '__wrapped__') and not stop(f)
.tox/py38/lib/python3.8/site-packages/werkzeug/local.py:316: in __get__
    obj = instance._get_current_object()  # type: ignore[misc]
.tox/py38/lib/python3.8/site-packages/werkzeug/local.py:509: in _get_current_object
    raise RuntimeError(unbound_message) from None
E   RuntimeError: Working outside of application context.
E   
E   This typically means that you attempted to use functionality that needed
E   the current application. To solve this, set up an application context
E   with app.app_context(). See the documentation for more information.
=============================================================================== warnings summary ===============================================================================
.tox/py38/lib/python3.8/site-packages/_pytest/doctest.py:479
  /workspace/scholia/.tox/py38/lib/python3.8/site-packages/_pytest/doctest.py:479: PytestWarning: Got RuntimeError('Working outside of application context.\n\nThis typically means that you attempted to use functionality that needed\nthe current application. To solve this, set up an application context\nwith app.app_context(). See the documentation for more information.') when unwrapping <LocalProxy unbound>.  This is usually caused by a violation of Python's object protocol; see e.g. https://github.com/pytest-dev/pytest/issues/5080
    warnings.warn(

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
=========================================================================== short test summary info ============================================================================
ERROR scholia/app/views.py - RuntimeError: Working outside of application context.
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
========================================================================= 1 warning, 1 error in 0.71s ==========================================================================
ERROR: InvocationError for command /workspace/scholia/.tox/py38/bin/python -m pytest --doctest-modules scholia (exited with code 2)
py39 create: /workspace/scholia/.tox/py39
ERROR: InterpreterNotFound: python3.9
___________________________________________________________________________________ summary ____________________________________________________________________________________
ERROR:   flake8: commands failed
  pydocstyle: commands succeeded
ERROR:  py37: InterpreterNotFound: python3.7
ERROR:   py38: commands failed
ERROR:  py39: InterpreterNotFound: python3.9

Expected behavior Tox runs through.

fnielsen commented 2 years ago

There are some notes at https://github.com/WDscholia/scholia/issues/2081

fnielsen commented 2 years ago

I do not get this commit a812e58400eae3af3eac62196b48803893fba0c6 completes tox with no problem...!?

carlinmack commented 2 years ago

I just checked out master and ran tox:

===================================================== 14 passed in 19.42s ======================================================
___________________________________________________________ summary ____________________________________________________________
  flake8: commands succeeded
  pydocstyle: commands succeeded
ERROR:  py37: InterpreterNotFound: python3.7
  py38: commands succeeded
  py39: commands succeeded

I'm not sure how tox accesses the different versions of Python, I don't think I have 3.7 installed

fnielsen commented 2 years ago

The different Python versions needs to be installed. I have used deadsnakes in some cases.

fnielsen commented 2 years ago

I can make it complete now:

  flake8: commands succeeded
  pydocstyle: commands succeeded
  py37: commands succeeded
  py38: commands succeeded
  py39: commands succeeded
  congratulations :)

I am not sure what was wrong, but it seems to run ok now., - as far as I can tell.

fnielsen commented 2 years ago

Please reopen if there still is a problem.