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

Using logger from pytest_runtest_logreport() #4810

Closed
mitzkia opened this Issue Feb 19, 2019 · 6 comments

Comments

Projects
None yet
2 participants
@mitzkia
Copy link

mitzkia commented Feb 19, 2019

Hi,

I have a following files with contents:
I would expect that log message from pytest_runtest_logreport() also appears in log-file.txt.
As far as I know pytest_runtest_logreport() runs after the setup, call and teardown methods.

conftest.py

import logging
logger = logging.getLogger(__name__)

def pytest_runtest_setup(item):
    logger.info("logger - from setup")

def pytest_runtest_call(item):
    logger.info("logger - from call")

def pytest_runtest_teardown(item):
    logger.info("logger - from teardown")

def pytest_runtest_logreport(report):
    logger.info("logger - from logreport")

test_example.py

def test_example():
    assert False

starter command

python3 -m pytest --log-level=debug --log-file=log-file.txt -lvs test_example.py

log-file.txt content:

conftest.py                  5 INFO     logger - from setup
conftest.py                  8 INFO     logger - from call
conftest.py                 11 INFO     logger - from teardown

Thanks for the help.

@mitzkia

This comment has been minimized.

Copy link
Author

mitzkia commented Feb 19, 2019

If pytest is not supports currently this method, could it be a relevant fix/update?

@nicoddemus

This comment has been minimized.

Copy link
Member

nicoddemus commented Feb 19, 2019

Hi @mitzkia,

Indeed it is a bug. We should be catching logging calls around pytest_runtest_logreport, similar to what we do for pytest_runtest_logfinish (for example):

@pytest.hookimpl(hookwrapper=True)
def pytest_runtest_logfinish(self):
with self._runtest_for(None, "finish"):
yield

@mitzkia

This comment has been minimized.

Copy link
Author

mitzkia commented Feb 20, 2019

Hi @nicoddemus,

Thank you for the answer.
I did not know yet how hard this issue, but I will start to resolve it.

@nicoddemus

This comment has been minimized.

Copy link
Member

nicoddemus commented Feb 20, 2019

Oh a PR would certainly be appreciated!

@mitzkia

This comment has been minimized.

Copy link
Author

mitzkia commented Feb 20, 2019

I think the PR will work (just tried something which seems to be work)

@mitzkia

This comment has been minimized.

Copy link
Author

mitzkia commented Feb 20, 2019

Related PR #4812

@nicoddemus nicoddemus closed this Feb 22, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.
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.