-
Notifications
You must be signed in to change notification settings - Fork 244
Configure logging format #478
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
Comments
you need to configure your logging, this one is a good starting point: |
Not sure if it's working now. Here is my minimal example import logging
import pytest
def test_one():
# put configuration here, so it definitely run
logging.basicConfig(level = logging.DEBUG,format = '[%(asctime)s] %(levelname)s - %(message)s')
logging.warning('from test_one')
if __name__ == '__main__':
test_one() If I just run function, it's logged properly > python3 test.py
[2022-01-16 20:30:29,233] WARNING - from test_one But if I run it in pytest, logs in report does not change > pytest test.py --html=report.html --self-contained-html |
Hello, I have the same issue. I'd need to see the datetime information from each log message in the test report, as seen in the console. There is a comment from @BeyondEvil in issue #314 314#issuecomment-659253438 that seems to highlight that, since you are getting Is there any known workaround to achieve prints with date time information inside the pytest-html report? Is there any plan to add this feature? Thank you! |
This issue is not caused by
|
The plugin doesn't do any manipulation of the logs. Could you provide a reproducible example? |
Environment pytest setting in pyproject.toml testpaths = ["auto_tests"] The result is the format of the capture in the report.html is different from what actually print out in the console. |
I see the issue between the live log and the captured log even in v4. But I don't think this is an issue with the plugin as we only basically copy and paste what we get from pytest: Do note that the captured log in the report matches what's in the captured log that is in the console. We don't add live log to the report. |
@chansonjoy - aren't your options
I'm not sure what to expect with that. In any case, I've never used pyproject.toml to specify my pytest ini options. I always just use plain pytest.ini. Can you try that to see if you get the same behavior you reported? |
you are absolutely right. I think the later "--capture=tee-sys" overwrite the "-s" though. Anyway, I tried simplify the parameters and put them in pytest.ini as: [pytest] testpaths = auto_tests The print from the report.html still different from print from the terminal as the following side by side comparison: |
Right - so a couple of things.
|
Thanks for pointing out the difference between live log and captured log. From this link it seems to me pytest will automatically add a log handler which is passed to the pytest-html according to @BeyondEvil. This logger format can be set in the pytest.ini or pyproject.toml. And I believe this log handler emit to the sys.stdout by default. The following is my setup in pyproject.toml. which finally get the print in console and html identical. Notice that from above setting, I only need to set log_cli to true to turn on the live log. because the default pyest sys.stdout logger already been formatted previously. And then in the test code, just get a logger from the module without any formatting needed. |
I'm going to close this now. Please feel free to reopen if there's still an issue. |
Hi. I would like to have a possibility to set logging format. Didn't find anything about it in documentation. Tried to modify format from logging library or pytest settings, but it didn't change output in html (maybe i didn't find the right knob?). My versions:
So for now this code
generate

And I want something like
[2022-01-02 01:00:24,052] WARNING from test_one
[2022-01-02 01:00:24,052] WARNING from test_two
The text was updated successfully, but these errors were encountered: