WDscholia / scholia

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

Tox testing erros with "RuntimeError: Working outside of application context." #2081

Closed fnielsen closed 2 years ago

fnielsen commented 2 years ago
$ tox -e py37
GLOB sdist-make: ../scholia/setup.py
py37 inst-nodeps: ../scholia/.tox/.tmp/package/1/scholia-0.3+257.gb0c500c.zip
WARNING: Discarding $PYTHONPATH from environment, to override specify PYTHONPATH in 'passenv' in your configuration.
py37 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,flask-mwoauth==0.4.82,future==0.18.2,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,mwoauth==0.3.8,oauthlib==3.2.0,packaging==21.3,pluggy==1.0.0,py==1.11.0,PyJWT==2.4.0,pyparsing==3.0.9,pytest==7.1.2,python-dateutil==2.8.2,requests==2.28.1,requests-oauthlib==1.3.1,scholia==0.3+257.gb0c500c,sgmllib3k==1.0.0,simplejson==3.17.6,six==1.16.0,tomli==2.0.1,typing_extensions==4.3.0,urllib3==1.26.11,visitor==0.1.3,Werkzeug==2.2.1,zipp==3.8.1
py37 run-test-pre: PYTHONHASHSEED='1347084808'
py37 run-test: commands[0] | python -m pytest --doctest-modules scholia
================================================== test session starts ==================================================
platform linux -- Python 3.7.13, pytest-7.1.2, pluggy-1.0.0
cachedir: .tox/py37/.pytest_cache
rootdir: ../scholia
collected 62 items / 1 error                                                                                            

======================================================== ERRORS =========================================================
_________________________________________ ERROR collecting scholia/app/views.py _________________________________________
/usr/lib/python3.7/doctest.py:939: in find
    self._find(tests, obj, name, module, source_lines, globs, {})
.tox/py37/lib/python3.7/site-packages/_pytest/doctest.py:534: in _find
    tests, obj, name, module, source_lines, globs, seen
/usr/lib/python3.7/doctest.py:998: in _find
    if ((inspect.isroutine(inspect.unwrap(val))
.tox/py37/lib/python3.7/site-packages/_pytest/doctest.py:475: in _mock_aware_unwrap
    return real_unwrap(func, stop=_is_mocked)
/usr/lib/python3.7/inspect.py:511: in unwrap
    while _is_wrapper(func):
/usr/lib/python3.7/inspect.py:505: in _is_wrapper
    return hasattr(f, '__wrapped__') and not stop(f)
.tox/py37/lib/python3.7/site-packages/werkzeug/local.py:316: in __get__
    obj = instance._get_current_object()  # type: ignore[misc]
.tox/py37/lib/python3.7/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/py37/lib/python3.7/site-packages/_pytest/doctest.py:483
  ../scholia/.tox/py37/lib/python3.7/site-packages/_pytest/doctest.py:483: 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
    PytestWarning,

-- 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.51s ==============================================
ERROR: InvocationError for command ../scholia/.tox/py37/bin/python -m pytest --doctest-modules scholia (exited with code 2)
________________________________________________________ summary ________________________________________________________
ERROR:   py37: commands failed

There are no doctest commands in views.py, but it seems that doctest is trying to collect doctests from there and then errs. As far as I know this has been working before, so perhaps a recent update of py.test has done something? Would it be possible to ignore that file?

fnielsen commented 2 years ago
fnielsen commented 2 years ago

Possibly related to https://github.com/pytest-dev/pytest/issues/8676

fnielsen commented 2 years ago

Would in tox.ini this helps:

deps=
    pytest==6.2.1
fnielsen commented 2 years ago

No. "Python 3.7.13, pytest-6.2.1, py-1.11.0, pluggy-0.13.1" with tox does not help

fnielsen commented 2 years ago
fnielsen commented 2 years ago
tox --version
3.20.1 imported from /usr/local/lib/python3.8/dist-packages/tox/__init__.py
WolfgangFahl commented 2 years ago

The jenkins nightly build of the night before ran just fine. While it's been in an on/off state for the past few days and failed tonight. It seems for other reasons,though. This morning i restarted the py39 tests and they ran ok. I couldn't get py310 running, though - no tests would be started.

.tox/py39/lib/python3.9/site-packages/requests/models.py:917: JSONDecodeError
=========================== short test summary info ============================
FAILED tests/test_text.py::test_text_to_topic_q_text - requests.exceptions.JS...
=================== 1 failed, 13 passed in 67.31s (0:01:07) ====================

grafik

py39 run-test-pre: PYTHONHASHSEED='3304998157'
py39 run-test: commands[0] | python -m pytest --doctest-modules scholia
============================= test session starts ==============================
platform linux -- Python 3.9.13, pytest-7.1.2, pluggy-1.0.0
cachedir: .tox/py39/.pytest_cache
rootdir: /hd/luxio/var/lib/jenkins/jobs/scholia/workspace
collected 63 items

scholia/api.py .........                                                 [ 14%]
scholia/arxiv.py ..                                                      [ 17%]
scholia/github.py .                                                      [ 19%]
scholia/googlescholar.py .                                               [ 20%]
scholia/model.py ..                                                      [ 23%]
scholia/query.py .................................                       [ 76%]
scholia/tex.py ...                                                       [ 80%]
scholia/utils.py ...                                                     [ 85%]
scholia/wikipedia.py .                                                   [ 87%]
scholia/scrape/jmlr.py .                                                 [ 88%]
scholia/scrape/nips.py ...                                               [ 93%]
scholia/scrape/ojs.py ....                                               [100%]

============================= 63 passed in 21.71s ==============================
py39 run-test: commands[1] | python -m pytest tests
============================= test session starts ==============================
platform linux -- Python 3.9.13, pytest-7.1.2, pluggy-1.0.0
cachedir: .tox/py39/.pytest_cache
rootdir: /hd/luxio/var/lib/jenkins/jobs/scholia/workspace
collected 14 items

tests/test_arxiv.py .                                                    [  7%]
tests/test_ask_query.py ...                                              [ 28%]
tests/test_query.py ....                                                 [ 57%]
tests/test_tex.py ...                                                    [ 78%]
tests/test_text.py .                                                     [ 85%]
tests/test_utils.py .                                                    [ 92%]
tests/scrape/test_ojs.py .                                               [100%]

============================= 14 passed in 30.16s ==============================
___________________________________ summary ____________________________________
  py39: commands succeeded
  congratulations :)
Finished: SUCCESS
fnielsen commented 2 years ago

Thanks for the information. I am very confused. I have now rerun tox on master and 2079-code-style-problem-in-viewspy-lines-too-lon and both completed (master had an unrelated error on wikitext = q_to_bibliography_templates("Q28923929" which is probably a network error for Python3.9). The setup is ,e.g., "Python 3.9.13, pytest-7.1.2, pluggy-1.0.0".

fnielsen commented 2 years ago

This is the same as https://github.com/WDscholia/scholia/issues/2076