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

Don't include any captured stdout/stderr/log output to the report #171

Closed
bigunyak opened this issue Jun 27, 2018 · 21 comments · Fixed by #359
Closed

Don't include any captured stdout/stderr/log output to the report #171

bigunyak opened this issue Jun 27, 2018 · 21 comments · Fixed by #359
Assignees
Labels
enhancement This issue/PR relates to a feature request. help wanted

Comments

@bigunyak
Copy link

Hi,
To reduce report file size, I'm trying to exclude any captured stdout/stderr/log output.
I'm running tests with the following command:

pytest --html=report.html --self-contained-html --capture=no --show-capture=no tests/

With this I still get the Captured log call section for every test no matter if it pass or not.
So the question, how to not include any captured output to the report?

@bigunyak
Copy link
Author

bigunyak commented Jun 27, 2018

The --show-capture option seems to have absolutely no effect on what gets included into the report.
Could you please help to understand how capturing suppose to work?

@davehunt
Copy link
Collaborator

--show-capture is not related to the HTML report, but I like the idea. I'll label this as an enhancement and maybe somebody would be interested in working on it. I don't think it would be too hard, we'd just need to get the value from the configuration and make the writing to the report conditional based on it.

@davehunt davehunt added enhancement This issue/PR relates to a feature request. help wanted labels Jun 27, 2018
@adriangb
Copy link

adriangb commented Sep 4, 2019

This honestly seems like a bug to me, not an enhancement. --capture=no should disable all capture.

@BeyondEvil
Copy link
Contributor

I agree with @adriangb.

What do you think @davehunt ?

@rochacbruno
Copy link
Collaborator

what I understood is that --capture is a pytest argument not a pytest-html argument.

So the enhancement would be adding the feature to read that arguments and do something.

@BeyondEvil
Copy link
Contributor

BeyondEvil commented Sep 5, 2019 via email

@adriangb
Copy link

adriangb commented Sep 5, 2019

what I understood is that --capture is a pytest argument not a pytest-html argument.

So the enhancement would be adding the feature to read that arguments and do something.

Yes, --capture and --show-capture are Pytest options, but regardless it would be nice to have these options in the plugin (there is a reason they exist in Pytest), so why not make the plugin follow whatever Pytest does? Then to go the extra mile --html-report-capture and --html-report-show-capture could be added which override --capture and --show-capture for the HTML report.

In terms of implementation, I am really very new to Pytest so take this with a grain of salt, but I noticed the same thing (capturing of log output despite use of --capture=no) happens with pytest-json and Junit XML reports, which leads me to thing that Pytest itself is not completely respecting the flag (if it was, these plugins should never be able to get the log output in the first place)

@davehunt
Copy link
Collaborator

I still think this is an enhancement, and a worthwhile one. Perhaps pytest should be more clear that the capture arguments only relate to the console logging, and that plugins are not required to respect them. If you disagree then I would suggest opening a bug against pytest that prevents plugins from having access to this content if the arguments are used.

Either way, I don't think we want to duplicate these arguments for each plugin.

@sjkcarnahan
Copy link

I would like to tack on that this would be a great option.

@hello-ming
Copy link

hello-ming commented Mar 24, 2020

Any progress here? It's better if we could control disabling stdout or stderr or all.

Wondering why captured stderr/log call contents are the same in my html report, I'm using xdist plugin

@kstsai
Copy link

kstsai commented May 6, 2020

FYI,

I used
pytest --html=1.htm --self-contained-html --capture=tee-sys

the generated 1.thm
DOES include captured stdout output nearby relevant test case.

@longelier
Copy link

longelier commented Jun 12, 2020

How I use stdout, is to display comments/messages as each test case progresses, and it shows up in the html report. So please don't change that.
I have multiple variables to check in each testcase and I want to show in the report what the value is at that point, before moving on. Call these checkpoints, and there are many before it gets to the final checkpoint...the completion of each test case. These extra messages tell me, and others reader, what the test case did and what values at that time of the message. Also some confidence that it ran as reader expected. Seeing just pass/fail on a report is not as helpful, but seeing it with some extra proof that it really did pass is.

Example output from html report, that each test case spits out:
-----------------------------Captured stdout setup------------------------------
(presetup) Starting.
------------------------------Captured stdout call------------------------------
(test_case1) Starting.
PASS1: Apple color matches 'red'.
FAIL2: Apple size does not match 'big'.
------------------------------Captured stderr call------------------------------
20200612 060306 INFO: (test_case1) Apple=(green)
-------------------------------Captured log call--------------------------------
[32mINFO [0m test_case1:test_case1.py:45 (test_case1) Apple=(green)

I like the idea of being able to disable/enable some or all of the capture.
In above 'Captured log call' section, I specifically used logging.info("test_case1) Apple=(green)") to display a message...and when I ran it at the command prompt, there were unexpected ASCII characters(that I don't want). It would be nice to disable this part of the capture.
Running within PyCharm doesn't show the ASCII, but I need it run at command line more than an IDE.

@yogeshwar1996
Copy link

Its anoying to have logs captured in html report. The file size becomes >1GB. Kindly add the feature to disable log capturing in report

@longelier
Copy link

Agreed. There should be a away disable each of out the outputs, so the html report does not include it...thereby keeping the file size smaller.
The output in my html report, is from my communicating with network switches, and can really accumulate in each of the below sections:

  1. Captured stdout setup
  2. Captured stderr setup
  3. Captured log setup
  4. Captured stdout call
  5. Captured stderr call
  6. Captured log call

@NicolasAgra
Copy link

I just have found this issue and I am having a similar problem but maybe I should create another one. Let me know @davehunt . I created a logger to see in live the logs through the normal stdout stream my customs messages and avoid dependency logs. I usually run in the terminal individual tests with the "-s" option to see logs in live. However, when I do this with the --html option, the report generates just fine but I get all duplicated when showing:

 ------------------------------Captured stdout call------------------------------ 
21:16:20.224 - INFO - 

TEST DESCRIPTION: Some description
21:16:20.849 - INFO - 🏃 MSJ: {"error":"invalid_token"}

 -------------------------------Captured log call-------------------------------- 
INFO     mylib.py:36 

TEST DESCRIPTION: Some description
INFO     mylib.py:24 MSJ: {"error":"invalid_token"}

Is there a way to avoid log call? Since the option "--no-print-logs" was deprecated from older versions of pytest, the option "--show-capture-logs=no" does not apply in the same way. I have the latest versions:

pytest==6.1.1
pytest-csv==2.0.2
pytest-forked==1.3.0
pytest-html==2.1.1
pytest-metadata==1.10.0
pytest-reportportal==5.0.5
pytest-sugar==0.9.4
pytest-xdist==2.1.0

My log definition:

import sys
import logging

# Logging stuff
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)

# Define messages format
formatter = logging.Formatter('%(asctime)s.%(msecs)03d - %(levelname)s - %(message)s', datefmt='%H:%M:%S')

# Define handler
handler = logging.StreamHandler(sys.stdout)
handler.setFormatter(formatter)
logger.addHandler(handler)

Regards!

@BeyondEvil
Copy link
Contributor

This has been a long running issue. Would @gnikonorov or @ssbarnea have some time to just take a quick look to see if there's an easy/fast fix for this?

@gnikonorov
Copy link
Member

This has been a long running issue. Would @gnikonorov or @ssbarnea have some time to just take a quick look to see if there's an easy/fast fix for this?

I can take a look @BeyondEvil!

@swbchangle
Copy link

should_skip_captured_output = pytest_capture_value == "no"
if report.outcome == "failed" and not should_skip_captured_output:
    should_skip_captured_output = pytest_show_capture_value == "no"
if not should_skip_captured_output:
    self._populate_html_log_div(log, report)

From this code I understand that
If --capture is not "no", pytest-html puts it in html unless --show-capture=no is specified.
If --capture=no , pytest-html ignores anything in stdout/stderr/log, regardless of --show-capture=no specified or not.

But --capture only controls stdout/stderr. I am using logging module to log messages. I set --capture=no. In this case, nothing will be logged in html.

@mubarakl-netapp
Copy link

I am still facing thi

I just have found this issue and I am having a similar problem but maybe I should create another one. Let me know @davehunt . I created a logger to see in live the logs through the normal stdout stream my customs messages and avoid dependency logs. I usually run in the terminal individual tests with the "-s" option to see logs in live. However, when I do this with the --html option, the report generates just fine but I get all duplicated when showing:

 ------------------------------Captured stdout call------------------------------ 
21:16:20.224 - INFO - 

TEST DESCRIPTION: Some description
21:16:20.849 - INFO - 🏃 MSJ: {"error":"invalid_token"}

 -------------------------------Captured log call-------------------------------- 
INFO     mylib.py:36 

TEST DESCRIPTION: Some description
INFO     mylib.py:24 MSJ: {"error":"invalid_token"}

Is there a way to avoid log call? Since the option "--no-print-logs" was deprecated from older versions of pytest, the option "--show-capture-logs=no" does not apply in the same way. I have the latest versions:

pytest==6.1.1
pytest-csv==2.0.2
pytest-forked==1.3.0
pytest-html==2.1.1
pytest-metadata==1.10.0
pytest-reportportal==5.0.5
pytest-sugar==0.9.4
pytest-xdist==2.1.0

My log definition:

import sys
import logging

# Logging stuff
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)

# Define messages format
formatter = logging.Formatter('%(asctime)s.%(msecs)03d - %(levelname)s - %(message)s', datefmt='%H:%M:%S')

# Define handler
handler = logging.StreamHandler(sys.stdout)
handler.setFormatter(formatter)
logger.addHandler(handler)

Regards!

I am also facing this issue. Is there any fix or workaround? Please help

@QiaoqinXiao
Copy link

I just have found this issue and I am having a similar problem but maybe I should create another one. Let me know @davehunt . I created a logger to see in live the logs through the normal stdout stream my customs messages and avoid dependency logs. I usually run in the terminal individual tests with the "-s" option to see logs in live. However, when I do this with the --html option, the report generates just fine but I get all duplicated when showing:

 ------------------------------Captured stdout call------------------------------ 
21:16:20.224 - INFO - 

TEST DESCRIPTION: Some description
21:16:20.849 - INFO - 🏃 MSJ: {"error":"invalid_token"}

 -------------------------------Captured log call-------------------------------- 
INFO     mylib.py:36 

TEST DESCRIPTION: Some description
INFO     mylib.py:24 MSJ: {"error":"invalid_token"}

Is there a way to avoid log call? Since the option "--no-print-logs" was deprecated from older versions of pytest, the option "--show-capture-logs=no" does not apply in the same way. I have the latest versions:

pytest==6.1.1
pytest-csv==2.0.2
pytest-forked==1.3.0
pytest-html==2.1.1
pytest-metadata==1.10.0
pytest-reportportal==5.0.5
pytest-sugar==0.9.4
pytest-xdist==2.1.0

My log definition:

import sys
import logging

# Logging stuff
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)

# Define messages format
formatter = logging.Formatter('%(asctime)s.%(msecs)03d - %(levelname)s - %(message)s', datefmt='%H:%M:%S')

# Define handler
handler = logging.StreamHandler(sys.stdout)
handler.setFormatter(formatter)
logger.addHandler(handler)

Regards!

Do you have any solutions? I am also facing this issue, because the duplicated logs, it has difficult to check the failures via log.

@BeyondEvil
Copy link
Contributor

@QiaoqinXiao

try 4.0.0rc4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement This issue/PR relates to a feature request. help wanted
Projects
None yet
Development

Successfully merging a pull request may close this issue.