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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't capture logs #8

Closed
bnavigator opened this issue Jun 5, 2022 · 1 comment · Fixed by #12
Closed

Can't capture logs #8

bnavigator opened this issue Jun 5, 2022 · 1 comment · Fixed by #12

Comments

@bnavigator
Copy link

Hi,

I am trying to package this inside a rpmbuild environment, and running the unittests is mandatory. Currently the test suite fails because the fixture is unable to capture the log, although the expected output is in stderr:

 [    9s] + pytest-3.9 --ignore=_build.python39 --ignore=_build.python310 --ignore=_build.python38 -v notebook_shim
[    9s] ============================= test session starts ==============================
[    9s] platform linux -- Python 3.9.13, pytest-7.1.1, pluggy-1.0.0 -- /usr/bin/python3.9
[    9s] cachedir: .pytest_cache
[    9s] rootdir: /home/abuild/rpmbuild/BUILD/notebook_shim-0.1.0, configfile: pyproject.toml
[    9s] plugins: tornasync-0.6.0.post2, console-scripts-1.3.1, anyio-3.5.0
[    9s] collecting ... collected 10 items
[    9s] 
[    9s] notebook_shim/tests/test_extension.py::test_EXTAPP_AND_NBAPP_SHIM_MSG[jp_argv0-enable_mathjax-False] FAILED [ 10%]
[    9s] notebook_shim/tests/test_extension.py::test_EXTAPP_AND_SVAPP_SHIM_MSG[jp_argv0-allow_origin-] FAILED [ 20%]
[    9s] notebook_shim/tests/test_extension.py::test_EXTAPP_AND_SVAPP_SHIM_MSG[jp_argv1-allow_origin_pat-] FAILED [ 30%]
[    9s] notebook_shim/tests/test_extension.py::test_NOT_EXTAPP_NBAPP_AND_SVAPP_SHIM_MSG[jp_argv0-jinja_environment_options-trait_value0] FAILED [ 40%]
[   10s] notebook_shim/tests/test_extension.py::test_NOT_EXTAPP_NBAPP_AND_SVAPP_SHIM_MSG[jp_argv1-jinja_template_vars-trait_value1] FAILED [ 50%]
[   10s] notebook_shim/tests/test_extension.py::test_NOT_EXTAPP_NBAPP_AND_SVAPP_SHIM_MSG[jp_argv2-extra_template_paths-trait_value2] FAILED [ 60%]
[   10s] notebook_shim/tests/test_extension.py::test_NOT_EXTAPP_NBAPP_AND_SVAPP_SHIM_MSG[jp_argv3-quit_button-True] FAILED [ 70%]
[   10s] notebook_shim/tests/test_extension.py::test_EXTAPP_TO_SVAPP_SHIM_MSG[jp_argv0-allow_credentials-False] FAILED [ 80%]
[   10s] notebook_shim/tests/test_extension.py::test_EXTAPP_TO_NBAPP_SHIM_MSG[jp_argv0-mathjax_config-TEST] FAILED [ 90%]
[   10s] notebook_shim/tests/test_extension.py::test_EXTAPP_TO_NBAPP_SHIM_MSG[jp_argv1-mathjax_url-TEST] FAILED [100%]
[   10s] 
[   10s] =================================== FAILURES ===================================
[   10s] ________ test_EXTAPP_AND_NBAPP_SHIM_MSG[jp_argv0-enable_mathjax-False] _________
[   10s] 
[   10s] extensionapp = <notebook_shim.tests.mockextension.MockExtensionApp object at 0x7f93a3d11550>
[   10s] extapp_log = <_io.StringIO object at 0x7f93a3db3f70>
[   10s] jp_argv = ['--MockExtensionApp.enable_mathjax=False']
[   10s] trait_name = 'enable_mathjax', trait_value = False
[   10s] 
[   10s]     @pytest.mark.parametrize(
[   10s]         'jp_argv,trait_name,trait_value',
[   10s]         list_test_params([
[   10s]             ('enable_mathjax', False)
[   10s]         ])
[   10s]     )
[   10s]     def test_EXTAPP_AND_NBAPP_SHIM_MSG(
[   10s]         extensionapp,
[   10s]         extapp_log,
[   10s]         jp_argv,
[   10s]         trait_name,
[   10s]         trait_value
[   10s]     ):
[   10s]         log = extapp_log.getvalue()
[   10s]         # Verify a shim warning appeared.
[   10s]         log_msg = shim.EXTAPP_AND_NBAPP_SHIM_MSG(trait_name, 'MockExtensionApp')
[   10s] >       assert log_msg in log
[   10s] E       assert "'enable_mathjax' is found in both MockExtensionApp and NotebookApp. This is a recent change. This config will only be set in MockExtensionApp. Please check if you should also config these traits in NotebookApp for your purpose." in ''
[   10s] 
[   10s] notebook_shim/tests/test_extension.py:89: AssertionError
[   10s] ---------------------------- Captured stderr setup -----------------------------
[   10s] [D 2022-06-05 18:18:08.822 ServerApp] Config changed: {'ServerApp': {'jpserver_extensions': {'notebook_shim': True, 'notebook_shim.tests.mockextension': True}}, 'NotebookNotary': {'db_file': ':memory:'}}
[   10s] [W 2022-06-05 18:18:08.839 MockExtensionApp] 'enable_mathjax' is found in both MockExtensionApp and NotebookApp. This is a recent change. This config will only be set in MockExtensionApp. Please check if you should also config these traits in NotebookApp for your purpose.
[   10s] ------------------------------ Captured log setup ------------------------------
[   10s] DEBUG    ServerApp:application.py:174 Searching ['/home/abuild/rpmbuild/BUILD/notebook_shim-0.1.0', '/tmp/pytest-of-abuild/pytest-19/test_EXTAPP_AND_NBAPP_SHIM_MSG0/config', '/home/abuild/.local/etc/jupyter', '/tmp/pytest-of-abuild/pytest-19/test_EXTAPP_AND_NBAPP_SHIM_MSG0/env/etc/jupyter', '/tmp/pytest-of-abuild/pytest-19/test_EXTAPP_AND_NBAPP_SHIM_MSG0/etc/jupyter'] for config files
[   10s] DEBUG    ServerApp:application.py:837 Looking for jupyter_config in /tmp/pytest-of-abuild/pytest-19/test_EXTAPP_AND_NBAPP_SHIM_MSG0/etc/jupyter
[   10s] DEBUG    ServerApp:application.py:837 Looking for jupyter_config in /tmp/pytest-of-abuild/pytest-19/test_EXTAPP_AND_NBAPP_SHIM_MSG0/env/etc/jupyter
[   10s] DEBUG    ServerApp:application.py:837 Looking for jupyter_config in /home/abuild/.local/etc/jupyter
[   10s] DEBUG    ServerApp:application.py:837 Looking for jupyter_config in /tmp/pytest-of-abuild/pytest-19/test_EXTAPP_AND_NBAPP_SHIM_MSG0/config
[   10s] DEBUG    ServerApp:application.py:837 Looking for jupyter_config in /home/abuild/rpmbuild/BUILD/notebook_shim-0.1.0
[   10s] DEBUG    ServerApp:application.py:837 Looking for jupyter_server_config in /tmp/pytest-of-abuild/pytest-19/test_EXTAPP_AND_NBAPP_SHIM_MSG0/etc/jupyter
[   10s] DEBUG    ServerApp:application.py:837 Looking for jupyter_server_config in /tmp/pytest-of-abuild/pytest-19/test_EXTAPP_AND_NBAPP_SHIM_MSG0/env/etc/jupyter
[   10s] DEBUG    ServerApp:application.py:837 Looking for jupyter_server_config in /home/abuild/.local/etc/jupyter
[   10s] DEBUG    ServerApp:application.py:837 Looking for jupyter_server_config in /tmp/pytest-of-abuild/pytest-19/test_EXTAPP_AND_NBAPP_SHIM_MSG0/config
[   10s] DEBUG    ServerApp:application.py:837 Looking for jupyter_server_config in /home/abuild/rpmbuild/BUILD/notebook_shim-0.1.0
[   10s] DEBUG    ServerApp:config_manager.py:97 Paths used for configuration of jupyter_server_config: 
[   10s]        /tmp/pytest-of-abuild/pytest-19/test_EXTAPP_AND_NBAPP_SHIM_MSG0/etc/jupyter/jupyter_server_config.json
[   10s] DEBUG    ServerApp:config_manager.py:97 Paths used for configuration of jupyter_server_config: 
[   10s]        /tmp/pytest-of-abuild/pytest-19/test_EXTAPP_AND_NBAPP_SHIM_MSG0/env/etc/jupyter/jupyter_server_config.json
[   10s] DEBUG    ServerApp:config_manager.py:97 Paths used for configuration of jupyter_server_config: 
[   10s]        /home/abuild/.local/etc/jupyter/jupyter_server_config.json
[   10s] DEBUG    ServerApp:config_manager.py:97 Paths used for configuration of jupyter_server_config: 
[   10s]        /tmp/pytest-of-abuild/pytest-19/test_EXTAPP_AND_NBAPP_SHIM_MSG0/config/jupyter_server_config.json
[   10s] DEBUG    ServerApp:config_manager.py:97 Paths used for configuration of jupyter_server_config: 
[   10s]        /home/abuild/rpmbuild/BUILD/notebook_shim-0.1.0/jupyter_server_config.d/notebook_shim.json
[   10s]        /home/abuild/rpmbuild/BUILD/notebook_shim-0.1.0/jupyter_server_config.json
[   10s] INFO     ServerApp:serverapp.py:2674 Serving notebooks from local directory: /tmp/pytest-of-abuild/pytest-19/test_EXTAPP_AND_NBAPP_SHIM_MSG0/root_dir
[   10s] INFO     ServerApp:serverapp.py:2674 Jupyter Server 1.15.6 is running at:
[   10s] INFO     ServerApp:serverapp.py:2674 http://localhost:34279/a%40b/?token=...
[   10s] INFO     ServerApp:serverapp.py:2674  or http://127.0.0.1:34279/a%40b/?token=...
[   10s] INFO     ServerApp:serverapp.py:2675 Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).

I have tried pytest -s, pytest -p no:logging, and checked that the extapp_logcapture is loaded during setup. I have run out of ideas.

@Zsailer
Copy link
Member

Zsailer commented Sep 8, 2022

Fixed by #12.

Looks like traitlets changed some things around logging that broke things in our test (we were doing an ugly hack to check the logs). I've made a much cleaner solution in #12.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants