allure-framework / allure-python

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

Add stdout and stderror capturing with python behave #393

Open Alpherie opened 5 years ago

Alpherie commented 5 years ago

I'm submitting a ...

What is the current behavior?

Output from stdout and stderror is not captured for the report when using allure-behave.

What is the expected behavior?

Stdout and stderror output should be available when viewing Overview for the test.

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

To have an easy way to see the test-related output for future debugging/bug reporting/etc.

Please tell us about your environment:

Ljancek commented 5 years ago

Any update?

Ljancek commented 5 years ago

Something news?

Ljancek commented 4 years ago

Any update? @sseliverstov

demetrissss commented 4 years ago

??

vishuhanda commented 3 years ago

any progress??

sseliverstov commented 3 years ago

@Alpherie @Ljancek @demetrissss @vishuhanda you can add a hook to the environment.py like this:

import allure

def after_scenario(context, scenario):
    stdout = context.stdout_capture.getvalue()
    stderr = context.stderr_capture.getvalue()
    if stdout:
        allure.attach(stdout, name="stdout", attachment_type=allure.attachment_type.TEXT)
    if stderr:
        allure.attach(stderr, name="stderr", attachment_type=allure.attachment_type.TEXT)
sseliverstov commented 3 years ago

Please do not close this issue. Probably in the next versions I will add captured automaticaly

Alpherie commented 2 years ago

@sseliverstov thank you, it worked!

TurboCoder13 commented 1 year ago

@Alpherie @Ljancek @demetrissss @vishuhanda you can add a hook to the environment.py like this:

import allure

def after_scenario(context, scenario):
    stdout = context.stdout_capture.getvalue()
    stderr = context.stderr_capture.getvalue()
    if stdout:
        allure.attach(stdout, name="stdout", attachment_type=allure.attachment_type.TEXT)
    if stderr:
        allure.attach(stderr, name="stderr", attachment_type=allure.attachment_type.TEXT)

I don't seem to get this to work..

Where are these values set:

context.stdout_capture context.stderr_capture

Are they just directly accessible through context? I get an error when I copy this code directly:

HOOK-ERROR in after_scenario: AttributeError: 'NoneType' object has no attribute 'getvalue'

Alpherie commented 1 year ago

@eitel13 Are they just directly accessible through context? I get an error when I copy this code directly:

They should be. How are you launching behave? I use formatter -f allure_behave.formatter:AllureFormatter

TurboCoder13 commented 1 year ago

@Alpherie

How are you launching behave? I use formatter

I like to run tests with the IDE UI and unfortunately, there's things that just "don't work" with Behave and the IDE UI (eg: PyCharm Behave does not support "--junit" parameter).

I think this is one of them.

This is what the code looks like:

def after_scenario(context, scenario):
    try:
        stdout = context.stdout_capture.getvalue()
        stderr = context.stderr_capture.getvalue()

        print(f"stdout: {stdout}")
        print(f"stderr: {stderr}")

        if stdout:
            allure.attach(
                stdout,
                name="stdout",
                attachment_type=allure.attachment_type.TEXT,
            )
        if stderr:
            allure.attach(
                stderr,
                name="stderr",
                attachment_type=allure.attachment_type.TEXT,
            )

    except AttributeError:
        print("No stdout/stderr captured")
    else:
        print("stdout/stderr captured")

If I run through terminal, then I get:

stdout:

stderr:

stdout/stderr captured

Running through UI, the AttributeError is raised. 🙃