You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Indeed those docs are incomplete, we should add an example on how to customize it. set_log_path() is a method of LoggingPlugin, so it can be accessed from hooks or fixtures. We could add an example like this:
I was trying to check set_log_path module.
pytest version: 6.2.2
it seems config.pluginmanager.get_plugin("logging-plugin") gives out None
def pytest_configure(config):
logging_plugin = config.pluginmanager.get_plugin("logging-plugin")
logging_plugin.set_log_path(str(dir/ filename))
I get Error as:
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR> File "/home/jthakur/vnv_syn_new/lib/python3.6/site-packages/_pytest/main.py", line 265, in wrap_session
INTERNALERROR> config._do_configure()
INTERNALERROR> File "/home/jthakur/vnv_syn_new/lib/python3.6/site-packages/_pytest/config/init.py", line 982, in _do_configure
INTERNALERROR> self.hook.pytest_configure.call_historic(kwargs=dict(config=self))
INTERNALERROR> File "/home/jthakur/vnv_syn_new/lib/python3.6/site-packages/pluggy/hooks.py", line 308, in call_historic
INTERNALERROR> res = self._hookexec(self, self.get_hookimpls(), kwargs)
INTERNALERROR> File "/home/jthakur/vnv_syn_new/lib/python3.6/site-packages/pluggy/manager.py", line 93, in _hookexec
INTERNALERROR> return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR> File "/home/jthakur/vnv_syn_new/lib/python3.6/site-packages/pluggy/manager.py", line 87, in
INTERNALERROR> firstresult=hook.spec.opts.get("firstresult") if hook.spec else False,
INTERNALERROR> File "/home/jthakur/vnv_syn_new/lib/python3.6/site-packages/pluggy/callers.py", line 208, in _multicall
INTERNALERROR> return outcome.get_result()
INTERNALERROR> File "/home/jthakur/vnv_syn_new/lib/python3.6/site-packages/pluggy/callers.py", line 80, in get_result
INTERNALERROR> raise ex[1].with_traceback(ex[2])
INTERNALERROR> File "/home/jthakur/vnv_syn_new/lib/python3.6/site-packages/pluggy/callers.py", line 187, in _multicall
INTERNALERROR> res = hook_impl.function(*args)
INTERNALERROR> File "/home/jthakur/trees/npu-stack/habanaqa/tests/graph_compiler/workloads/conftest.py", line 180, in pytest_configure
INTERNALERROR> logging_plugin.set_log_path(str(os.path.join(pytest.log_dir, "synpase_test.log")))
INTERNALERROR> AttributeError: 'NoneType' object has no attribute 'set_log_path'
I was trying to check set_log_path module. pytest version: 6.2.2 it seems config.pluginmanager.get_plugin("logging-plugin") gives out None def pytest_configure(config): logging_plugin = config.pluginmanager.get_plugin("logging-plugin") logging_plugin.set_log_path(str(dir/ filename))
I get Error as: INTERNALERROR> Traceback (most recent call last): INTERNALERROR> File "/home/jthakur/vnv_syn_new/lib/python3.6/site-packages/_pytest/main.py", line 265, in wrap_session INTERNALERROR> config._do_configure() INTERNALERROR> File "/home/jthakur/vnv_syn_new/lib/python3.6/site-packages/_pytest/config/init.py", line 982, in _do_configure INTERNALERROR> self.hook.pytest_configure.call_historic(kwargs=dict(config=self)) INTERNALERROR> File "/home/jthakur/vnv_syn_new/lib/python3.6/site-packages/pluggy/hooks.py", line 308, in call_historic INTERNALERROR> res = self._hookexec(self, self.get_hookimpls(), kwargs) INTERNALERROR> File "/home/jthakur/vnv_syn_new/lib/python3.6/site-packages/pluggy/manager.py", line 93, in _hookexec INTERNALERROR> return self._inner_hookexec(hook, methods, kwargs) INTERNALERROR> File "/home/jthakur/vnv_syn_new/lib/python3.6/site-packages/pluggy/manager.py", line 87, in INTERNALERROR> firstresult=hook.spec.opts.get("firstresult") if hook.spec else False, INTERNALERROR> File "/home/jthakur/vnv_syn_new/lib/python3.6/site-packages/pluggy/callers.py", line 208, in _multicall INTERNALERROR> return outcome.get_result() INTERNALERROR> File "/home/jthakur/vnv_syn_new/lib/python3.6/site-packages/pluggy/callers.py", line 80, in get_result INTERNALERROR> raise ex[1].with_traceback(ex[2]) INTERNALERROR> File "/home/jthakur/vnv_syn_new/lib/python3.6/site-packages/pluggy/callers.py", line 187, in _multicall INTERNALERROR> res = hook_impl.function(*args) INTERNALERROR> File "/home/jthakur/trees/npu-stack/habanaqa/tests/graph_compiler/workloads/conftest.py", line 180, in pytest_configure INTERNALERROR> logging_plugin.set_log_path(str(os.path.join(pytest.log_dir, "synpase_test.log"))) INTERNALERROR> AttributeError: 'NoneType' object has no attribute 'set_log_path'
logging plugin is registered in a configure hook marked as trylast if I'm not mistaken which is likely the reason, try mark your hook with @pytest.hookimpl(trylast=True). Let me know if it helps, if not I'll take a look
logging plugin is registered in a configure hook marked as trylast if I'm not mistaken which is likely the reason, try mark your hook with @pytest.hookimpl(trylast=True). Let me know if it helps, if not I'll take a look
@pytest.hookimpl(trylast=True)
def pytest_configure(config):
logging_plugin = config.pluginmanager.get_plugin("logging-plugin")
# Change color on existing log level
logging_plugin.log_cli_handler.formatter.add_color_level(logging.INFO, "cyan")
# Add color to a custom log level (a custom log level `SPAM` is already set up)
logging_plugin.log_cli_handler.formatter.add_color_level(logging.SPAM, "blue")
strange as this isn't documented. unfortunately, it didn't colour my logs in pytest stdout output.
Activity
FirePing32 commentedon Nov 28, 2020
@nicoddemus #4707 (comment)
Shouldn't this example be added to Docs ? (
set_log_filenamebe replaced withset_log_path)nicoddemus commentedon Dec 12, 2020
Hi @prakhargurunani, sorry for the delay!
Indeed those docs are incomplete, we should add an example on how to customize it.
set_log_path()is a method ofLoggingPlugin, so it can be accessed from hooks or fixtures. We could add an example like this:This configures the logging file to always write next to the root path using the current datetime.
FirePing32 commentedon Dec 12, 2020
@nicoddemus Ok. I will make a PR adding the example in #4707 with your addition.
jay746 commentedon Feb 2, 2021
I was trying to check set_log_path module.
pytest version: 6.2.2
it seems config.pluginmanager.get_plugin("logging-plugin") gives out None
def pytest_configure(config):
logging_plugin = config.pluginmanager.get_plugin("logging-plugin")
logging_plugin.set_log_path(str(dir/ filename))
I get Error as:
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR> File "/home/jthakur/vnv_syn_new/lib/python3.6/site-packages/_pytest/main.py", line 265, in wrap_session
INTERNALERROR> config._do_configure()
INTERNALERROR> File "/home/jthakur/vnv_syn_new/lib/python3.6/site-packages/_pytest/config/init.py", line 982, in _do_configure
INTERNALERROR> self.hook.pytest_configure.call_historic(kwargs=dict(config=self))
INTERNALERROR> File "/home/jthakur/vnv_syn_new/lib/python3.6/site-packages/pluggy/hooks.py", line 308, in call_historic
INTERNALERROR> res = self._hookexec(self, self.get_hookimpls(), kwargs)
INTERNALERROR> File "/home/jthakur/vnv_syn_new/lib/python3.6/site-packages/pluggy/manager.py", line 93, in _hookexec
INTERNALERROR> return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR> File "/home/jthakur/vnv_syn_new/lib/python3.6/site-packages/pluggy/manager.py", line 87, in
INTERNALERROR> firstresult=hook.spec.opts.get("firstresult") if hook.spec else False,
INTERNALERROR> File "/home/jthakur/vnv_syn_new/lib/python3.6/site-packages/pluggy/callers.py", line 208, in _multicall
INTERNALERROR> return outcome.get_result()
INTERNALERROR> File "/home/jthakur/vnv_syn_new/lib/python3.6/site-packages/pluggy/callers.py", line 80, in get_result
INTERNALERROR> raise ex[1].with_traceback(ex[2])
INTERNALERROR> File "/home/jthakur/vnv_syn_new/lib/python3.6/site-packages/pluggy/callers.py", line 187, in _multicall
INTERNALERROR> res = hook_impl.function(*args)
INTERNALERROR> File "/home/jthakur/trees/npu-stack/habanaqa/tests/graph_compiler/workloads/conftest.py", line 180, in pytest_configure
INTERNALERROR> logging_plugin.set_log_path(str(os.path.join(pytest.log_dir, "synpase_test.log")))
INTERNALERROR> AttributeError: 'NoneType' object has no attribute 'set_log_path'
jonathan-krpt commentedon May 4, 2022
I see the same. is there a solution for this?
symonk commentedon May 4, 2022
logging plugin is registered in a configure hook marked as
trylastif I'm not mistaken which is likely the reason, try mark your hook with@pytest.hookimpl(trylast=True). Let me know if it helps, if not I'll take a lookjonathan-krpt commentedon May 4, 2022
yeah its fixed mt issue, but didn't solve what I was trying to do (logging colours customisation):
https://docs.pytest.org/en/7.1.x/how-to/logging.html
strange as this isn't documented. unfortunately, it didn't colour my logs in pytest stdout output.
docs: document set_log_path() usage and hook examples