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

Test Progress Indicator Hides Stdout From Fixtures After Yield #3029

Closed
trrichard opened this issue Dec 13, 2017 · 4 comments
Closed

Test Progress Indicator Hides Stdout From Fixtures After Yield #3029

trrichard opened this issue Dec 13, 2017 · 4 comments
Labels
topic: reporting related to terminal output and user-facing messages and errors type: enhancement new feature or API change, should be merged into features branch

Comments

@trrichard
Copy link

trrichard commented Dec 13, 2017

Change to add progress indicator (that thing that says 100%) to pytest clobbers stdout from fixtures after yield on Ubuntu 14.04 LTS with anaconda python 3.6.3

Change that (probably) introduced the bug:
#2657

Replication instructions:
In the following example the word "postfix" should show up in both outputs. It only shows up in the second output where we have set the console output style to classic.
Create a test file:

import pytest

@pytest.fixture()
def fix():
    print("prefix")
    yield None
    print("postfix")

def test_thing(fix):
    print("in test")

Run the test with -s
pytest test.py -s
Output:

test.py prefix
in test
.

Disable the progress feature by creating a file pytest.ini

[pytest]
console_output_style=classic

Run the test with -s
pytest test.py -s
Output:

test.py prefix
in test
.postfix

Pip List

attrs (17.3.0)
certifi (2017.11.5)
pip (9.0.1)
pluggy (0.6.0)
py (1.5.2)
pytest (3.3.1)
setuptools (36.5.0.post20170921)
six (1.11.0)
wheel (0.30.0)
@pytestbot
Copy link
Contributor

GitMate.io thinks the contributor most likely able to help you is @nicoddemus.

@nicoddemus
Copy link
Member

Hey @trrichard thanks for writing!

What happens is that the progress indicator is triggered by the end of the test call phase; it works by writing enough spaces to reach the end of the line + the percentage indicator. Then the teardown execution happens (after the yield in the fixture), and the output gets printed past that.

When you use the classic style, only the . is written to the output at the end of the test call phase, and then you get the output from the teardown execution.

I see two options how to proceed here:

  1. Automatically revert to "classic" style when using -s: any output here will greatly mess up the progress indicator anyway;
  2. Display the output indicator after the teardown phase; this might be a problem because tests which fail setup won't have a teardown phase.

I'm personally included to 1) because it is the easiest one to implement and will provide the better UX in the end IMO, but would like to hear others options on this.

@nicoddemus nicoddemus added topic: reporting related to terminal output and user-facing messages and errors type: enhancement new feature or API change, should be merged into features branch labels Dec 14, 2017
@trrichard
Copy link
Author

Agreed. I think it's odd to print anything other than test seperation headers (such as ==== test_name.py ====) between tests when using the -s option.

I would do option 1 or don't print any progress message ( . included ) for tests with -s enabled.

@nicoddemus
Copy link
Member

Cool. Closing this then in favor of #3038. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: reporting related to terminal output and user-facing messages and errors type: enhancement new feature or API change, should be merged into features branch
Projects
None yet
Development

No branches or pull requests

3 participants