Skip to content

Test Progress Indicator Hides Stdout From Fixtures After Yield #3029

Closed

Description

@trrichard

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)

Activity

  1. pytestbot commented on Dec 13, 2017

    @pytestbot
    Contributor

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

  2. nicoddemus commented on Dec 14, 2017

    @nicoddemus
    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.

  3. added
    topic: reporting
    type: enhancement
    on Dec 14, 2017
  4. trrichard commented on Dec 15, 2017

    @trrichard
    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.

  5. nicoddemus commented on Dec 15, 2017

    @nicoddemus
    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    topic: reportingtype: enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions