[Pytest-commit] Issue #441: parametrized fixture + module scope + failing test + '-x' option = invalid fixture finalizer output (hpk42/pytest)

Jurko Gospodnetić issues-reply at bitbucket.org
Sat Feb 1 18:36:15 CET 2014


New issue 441: parametrized fixture + module scope + failing test + '-x' option = invalid fixture finalizer output
https://bitbucket.org/hpk42/pytest/issue/441/parametrized-fixture-module-scope-failing

Jurko Gospodnetić:

The following test demonstrates the issue. You can run it as a part of the internal pytest test suite.

```
import fnmatch

def test_module_fixture_finalizer_output_capture(testdir):
    """
    Demonstrates a fixture finalizer output capture defect in pytest 2.5.0.

    pytest should not allow any test script output to be displayed uncontrolled
    unless its output capture has been disabled.

    If we have a parametrized module scoped fixture and a failing test using
    that fixture then running the test suite with the '-x' option seems to
    produce uncaptured fixture finalizer output (first fixture parametrization
    only).

    """
    testdir.makepyfile(r"""\
import pytest

@pytest.fixture(scope="module", params=["A", "B"])
def ola(request):
    print("<I AM NOT HERE> fixture (%s)" % (request.param,))
    class frufru:
        def __init__(self, param):
            self.param = param
        def __call__(self):
            print("<I AM NOT HERE> finalizer <%s>" % (self.param,))
    request.addfinalizer(frufru(request.param))
    return request.param

def test_me(ola):
    print("<I AM NOT HERE> test <%s>" % (ola,))
    pytest.fail()
""")

    # Using '--tb=no' should prevent all regularly captured test output to be
    # displayed. Using '-q' simply removes some irrelevant test output thus
    # making this external test's failure output shorter.
    for extra_params in ([], ["-x"]):
        output = testdir.runpytest("--tb=no", "-q", *extra_params).stdout.lines
        for line_index, line in enumerate(output):
            assert "<I AM NOT HERE>" not in line
```

  Hope this helps.

  Best regards,
    Jurko Gospodnetić





More information about the pytest-commit mailing list