Skip to content

Garbage date-time is printed in the Captured log. #314

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

Closed
pawan7476 opened this issue Jul 13, 2020 · 20 comments · Fixed by #315
Closed

Garbage date-time is printed in the Captured log. #314

pawan7476 opened this issue Jul 13, 2020 · 20 comments · Fixed by #315

Comments

@pawan7476
Copy link

Garbage date-time is printed in the Captured log.

pytest-html report:

------------------------------ Captured log setup ------------------------------
�[32mINFO �[0m root:test_cyclic_switchover.py:26 Inside Setup
�[32mINFO �[0m root:test_cyclic_switchover.py:54
------------------------------ Captured log call -------------------------------
�[32mINFO �[0m root:test_cyclic_switchover.py:82
Switchover Process : SCM

pytest console log :

collected 4 items / 2 deselected / 2 selected

test_cyclic_switchover.py::test_process_switchover[SCM]
------------------------------------------------------------ live log setup -------------------------------------------------------------
2020-07-13 21:51:50 [ INFO] Inside Setup
(test_cyclic_switchover.py:26)
2020-07-13 21:51:50 [ INFO]
(test_cyclic_switchover.py:54)
------------------------------------------------------------- live log call -------------------------------------------------------------
2020-07-13 21:51:50 [ INFO]
Switchover Process : SCM (test_cyclic_switchover.py:82)
PASSED [ 50%]
test_cyclic_switchover.py::test_process_switchover[SAM]
------------------------------------------------------------- live log call -------------------------------------------------------------
2020-07-13 21:51:50 [ INFO]
Switchover Process : SAM (test_cyclic_switchover.py:82)
PASSED [100%]
----------------------------------------------------------- live log teardown -----------------------------------------------------------
2020-07-13 21:51:50 [ INFO] Inside Teardown (test_cyclic_switchover.py:60)

@BeyondEvil
Copy link
Contributor

Could you provide some more info @pawan7476 ?

  • OS and version
  • Python version
  • Pytest version
  • Plugin version
  • Default encoding of your OS

It'd be great if you could also provide a minimum reproducible test.

Thanks!

@pawan7476
Copy link
Author

Hi @BeyondEvil,

Please find the required details :

  • py==1.9.0
  • pycparser==2.20
  • PyNaCl==1.4.0
  • pyparsing==2.4.7
  • pytest==5.4.3
  • pytest-html==1.22.1
  • pytest-metadata==1.8.0
  • pytest-repeat==0.8.0
  • Python | 3.5.2
  • Packages | {'pluggy': '0.13.1', 'pytest': '5.4.3', 'py': '1.9.0'}
  • Platform | Linux-4.4.0-62-generic-x86_64-with-Ubuntu-16.04-xenial
  • Plugins | {'metadata': '1.8.0', 'html': '1.22.1', 'repeat': '0.8.0'}
  • OS Encoding | {UTF-8}

Reproducible steps:-

  1. Trigger pytest unit test
    NOW=date '+%F_%H:%M:%S'
    USER=whoami
    PWD=pwd
    REPORT_PATH="$PWD/report/RAFy_report_$NOW.html"

Trigger Pytest runs

pytest -v --count=1 test_cyclic_switchover.py -m process --html="$REPORT_PATH"

console live logs:
========================================================== test session starts ==========================================================
platform linux -- Python 3.5.2, pytest-5.4.3, py-1.9.0, pluggy-0.13.1 -- /home/pawkumar/cluster/RAFy/virtualenvironment/venv/bin/python3
cachedir: .pytest_cache
metadata: {'Platform': 'Linux-4.4.0-62-generic-x86_64-with-Ubuntu-16.04-xenial', 'Python': '3.5.2', 'Packages': {'pluggy': '0.13.1', 'pytest': '5.4.3', 'py': '1.9.0'}, 'Plugins': {'metadata': '1.8.0', 'html': '1.22.1', 'repeat': '0.8.0'}}
rootdir: /home/pawkumar/cluster/RAFy, inifile: pytest.ini
plugins: metadata-1.8.0, html-1.22.1, repeat-0.8.0
collected 4 items / 2 deselected / 2 selected

test_cyclic_switchover.py::test_process_switchover[SCM]
------------------------------------------------------------ live log setup -------------------------------------------------------------
2020-07-14 14:28:15 [ INFO] Inside Setup
(test_cyclic_switchover.py:23)
------------------------------------------------------------- live log call -------------------------------------------------------------
2020-07-14 14:28:15 [ INFO]
Switchover Process : SCM (test_cyclic_switchover.py:49)
PASSED [ 50%]
test_cyclic_switchover.py::test_process_switchover[SAM]
------------------------------------------------------------- live log call -------------------------------------------------------------
2020-07-14 14:28:15 [ INFO]
Switchover Process : SAM (test_cyclic_switchover.py:49)
PASSED [100%]
----------------------------------------------------------- live log teardown -----------------------------------------------------------
2020-07-14 14:28:15 [ INFO] Inside Teardown (test_cyclic_switchover.py:27)

pytest-html generated report logs:

Test Report.zip

@BeyondEvil
Copy link
Contributor

We only support python >=3.6. Could you try and see if this is reproducible with 1) a newer version of python and 2) a newer version of the plugin (latest is 2.1.1) @pawan7476

@pawan7476
Copy link
Author

Hi @BeyondEvil ,

I tried with

pytest-html==2.1.1
Python 3.6.8

But still facing the same issue.

@BeyondEvil
Copy link
Contributor

Thank @pawan7476

Let me try to reproduce.

@BeyondEvil
Copy link
Contributor

You need to add the assets folder to the zip-file.

You can also try using the --self-contained-html file.

@BeyondEvil
Copy link
Contributor

I'm having trouble reproducing this. Could you provide a small test-case/python file (or even a complete repo) to help with reproducing this error?

@pawan7476
Copy link
Author

Hi @BeyondEvil ,

Please find all the minimum sample conf , test scripts , run logs attached which will help reproducing the issue.

thanks
Pawan
Test Files.zip

@BeyondEvil
Copy link
Contributor

I've identified the root cause. The "garbage" that you're seeing are the ANSI color codes for the log levels.

See this PR

The solution (or workaround 🤔) is to pass --color=no on the command line or in pytest.ini as addopts = --color=no

@BeyondEvil
Copy link
Contributor

Ok, I've found a way to handle it properly in the plugin. Please use the workaround for now.

@pawan7476
Copy link
Author

@BeyondEvil I've tested with your workaround and it helped to stop printing ANSI color codes. My only gripe is that in the pytest-html plugin report captured log, the date time is not captured as it should be like on the console logs.

pytest-html captured logs:
-------------------------------Captured log setup------------------------------- INFO root:test_cyclic_switchover.py:22 Inside Setup -------------------------------Captured log call-------------------------------- INFO root:test_cyclic_switchover.py:48 Switchover Process : a
console logs
test_cyclic_switchover.py::test_process_switchover[a]
------------------------------------------------------------ live log setup -------------------------------------------------------------
2020-07-16 09:21:24 [ INFO] Inside Setup (test_cyclic_switchover.py:22)
------------------------------------------------------------- live log call -------------------------------------------------------------
2020-07-16 09:21:24 [ INFO] Switchover Process : a (test_cyclic_switchover.py:48)
PASSED [ 50%]

@pawan7476
Copy link
Author

if we capture date-time with logging info for pytest-html plugin captured logs that will be great 💯

Expected:
2020-07-16 09:21:24 [ INFO] Inside Setup (test_cyclic_switchover.py:22)
Actual :
INFO root:test_cyclic_switchover.py:22 Inside Setup

@BeyondEvil
Copy link
Contributor

BeyondEvil commented Jul 16, 2020

The issue is that the information we get from pytest is the captured logs. They don't contain the timestamp, only the live logs do.

Is there an easy way for us to get the live logs (if present) instead of the captured @nicoddemus ?

https://github.com/pytest-dev/pytest-html/blob/master/pytest_html/plugin.py#L278

So the timestamp is emitted by the python logging module and nothing is stored, so we won't be able to show that in the report.

BeyondEvil added a commit to BeyondEvil/pytest-html that referenced this issue Jul 16, 2020
BeyondEvil added a commit to BeyondEvil/pytest-html that referenced this issue Jul 16, 2020
@nicoddemus
Copy link
Member

It should be possible to configure the logging formatting using the various logging options.

Also there should be an option to disable log coloring.

Is there an easy way for us to get the live logs (if present) instead of the captured @nicoddemus ?

Unfortunately not at the moment, but I believe the two issues above should be fixable.

@BeyondEvil
Copy link
Contributor

It should be possible to configure the logging formatting using the various logging options.

I don't think the configuration of the formatting is the issue here, the information coming from the captured logs still contain the ANSI escape sequences, so for the report (when not using ansi2html) we need to strip those out.

Also there should be an option to disable log coloring.

Right, --color=no, or am I misunderstanding you?

Is there an easy way for us to get the live logs (if present) instead of the captured @nicoddemus ?

Unfortunately not at the moment, but I believe the two issues above should be fixable.

I made an attempt in #315

Is there a better approach?

@nicoddemus
Copy link
Member

Right, --color=no, or am I misunderstanding you?

That's right, but I mean there should be a separate option just for logging, say log_color or something.

@BeyondEvil
Copy link
Contributor

BeyondEvil commented Jul 16, 2020

Right, --color=no, or am I misunderstanding you?

That's right, but I mean there should be a separate option just for logging, say log_color or something.

Can't find any. Even if I could, I'm not sure how it would solve the issue? 🤔

That is, the issue with the ANSI escape sequence in the report. If we even think that is an issue...

Sorry, tired, maybe I'm missing something obvious here.

@nicoddemus
Copy link
Member

Sorry, tired, maybe I'm missing something obvious here.

I just we could suggest users to configure log_color to false, then pytest-html wouldn't see the color codes at all. But your PR takes care of that so I don't think we should worry about it.

@pawan7476
Copy link
Author

Is there an easy way for us to get the live logs (if present) instead of the captured @nicoddemus ?

@nicoddemus @BeyondEvil , Please let me know if implementation of the above is in the plan.

@BeyondEvil
Copy link
Contributor

Is there an easy way for us to get the live logs (if present) instead of the captured @nicoddemus ?

@nicoddemus @BeyondEvil , Please let me know if implementation of the above is in the plan.

Yes, I'll merge the fix and see if I can't make a release this weekend.

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.

3 participants