allure-framework / allure-python

Allure integrations for Python test frameworks
https://allurereport.org/
Apache License 2.0
725 stars 237 forks source link

There is no log output in allure #663

Closed nullpointer00 closed 1 year ago

nullpointer00 commented 2 years ago

[//]: # ( . Note: for support questions, please use Stackoverflow or Gitter. . This repository's issues are reserved for feature requests and bug reports. . . In case of any problems with Allure Jenkins plugin please use the following repository . to create an issue: https://github.com/jenkinsci/allure-plugin/issues . . Make sure you have a clear name for your issue. The name should start with a capital . letter and no dot is required in the end of the sentence. An example of good issue names: . . - The report is broken in IE11 . - Add an ability to disable default plugins . - Support emoji in test descriptions )

I'm submitting a ...

What is the current behavior?

Hi I was using Allure and found that the log message was not collected

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem

def test_method(logger) logger.info("hi") #Use fixtures to generate a logger if name == 'main': pytest.main(["-s", "--alluredir={}".format(DirInfo.report_dir.value),#Please replace the path "test_cases.py"]) result = os.system(r"allure serve {}".format(DirInfo.report_dir.value)) print("result={}".format(result)) image

What is the expected behavior?

I would like to see logs in the report

What is the motivation / use case for changing the behavior?

Please tell us about your environment:

Other information

[//]: # ( . e.g. detailed explanation, stacktraces, related issues, suggestions . how to fix, links for us to have more context, eg. Stackoverflow, Gitter etc )

delatrie commented 1 year ago

Hi, @nullpointer00 !

It's an old issue, but in case you or someone else is still struggling:

If I understand correctly, you're using logging module with pytest here. Please, refer to this manual on how to do it properly, it's quite comprehensive.

As a quick summary and one of the possible solutions, the following code should work:

import logging
import pytest

@pytest.fixture
def logger(caplog):
    caplog.set_level(logging.INFO)
    return logging.getLogger()

def test_method(logger):
    logger.info("hi")

Also, you can get rid of -s (i.e., --capture=no) option, since it has no effect on log capturing.

Note, that you should be able to see your log message in pytest's output if you make the test fails (e.g. with assert False). If the message is missing, that means you did something wrong. If you see the message for a failed test, this indicates that allure will be able to grab it.

If you have more questions on how to use logging with pytest you probably should use stackoverflow or a similar platform - better chance to get a quicker response.

I will close this issue in a week or two. If you are still sure that there is some problem with the allure-pytest code, please, let me know.