-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
capture is not resumed after using disabled()
context manager - impact capsys and capfd
#1993
Comments
I suspect that the call to See pytest/testing/test_capture.py Lines 502 to 516 in 3301a1c
@pytest.mark.parametrize('fixture', ['capsys', 'capfd'])
def test_disabled_capture_fixture(self, testdir, fixture):
testdir.makepyfile("""
def test_disabled({fixture}):
print('captured before')
with {fixture}.disabled():
print('while capture is disabled')
print('captured after')
""".format(fixture=fixture))
result = testdir.runpytest_subprocess()
result.stdout.fnmatch_lines("""
*while capture is disabled*
""")
assert 'captured before' not in result.stdout.str()
assert 'captured after' not in result.stdout.str() |
To have a better understanding, I elaborated the test case and it look like the use of Here are the results I am getting (still on Ubuntu 15.10 with pytest 3.0.3/master and python2.7/3.5):
Using the following script import os
import pytest
def _check(cap, expect_fd=False, with_readouterr=True, expected_text_twice=False):
print("sys output")
if expect_fd:
os.write(1, "fd output\n".encode("ascii"))
if with_readouterr:
out, err = cap.readouterr()
expected_text = "sys output\n%s" % ("fd output\n" if expect_fd else "")
if expected_text_twice:
expected_text += expected_text
assert out == expected_text
def test_capsys(capsys):
_check(capsys)
def test_capfd(capfd):
_check(capfd, expect_fd=True)
def test_capsys_resume___without_disabled___without_intermediate_readouterr(capsys):
_check(capsys, with_readouterr=False)
_check(capsys, expected_text_twice=True)
def test_capfd__resume___without_disabled___without_intermediate_readouterr(capfd):
_check(capfd, expect_fd=True, with_readouterr=False)
_check(capfd, expect_fd=True, expected_text_twice=True)
def test_capsys_resume___without_disabled___with____intermediate_readouterr(capsys):
_check(capsys)
_check(capsys)
def test_capfd__resume___without_disabled___with____intermediate_readouterr(capfd):
_check(capfd, expect_fd=True)
_check(capfd, expect_fd=True)
def test_capsys_resume___with____disabled___without_intermediate_readouterr(capsys):
_check(capsys, with_readouterr=False)
with capsys.disabled():
pass
_check(capsys, expected_text_twice=True)
def test_capfd__resume___with____disabled___without_intermediate_readouterr(capfd):
_check(capfd, expect_fd=True, with_readouterr=False)
with capfd.disabled():
pass
_check(capfd, expect_fd=True, expected_text_twice=True)
def test_capsys_resume___with____disabled___with____intermediate_readouterr(capsys):
_check(capsys)
with capsys.disabled():
pass
_check(capsys)
def test_capfd__resume___with____disabled___with____intermediate_readouterr(capfd):
_check(capfd, expect_fd=True)
with capfd.disabled():
pass
_check(capfd, expect_fd=True) |
This will facilitate fixing remaining issue. Since disabled() can not be used with readouterr [1], we refactor the code so that disabled() is called only once at the end of the test. [1] See pytest-dev/pytest#1993
I'm facing the same issue in Pytest 3.1.3 (see https://stackoverflow.com/questions/46153983/pytests-capsys-disabled-not-working-as-expected). |
I'm looking at this issue as well. In particular, I want to suppress "Requesting Pages: 0 through 19" in the output. ============================= test session starts ============================= ..\tests\test_requestor.py ..........Requesting Pages: 0 through 19 ========================== 11 passed in 1.13 seconds ========================== This doesn't work:
This does work but is ugly as heck.
|
@cdreimer Huh, it seems to me that |
@The-Compiler Perhaps I misunderstood the |
@cdreimer pytest does this by default unless you start it with |
@The-Compiler Looks like the PyCharm IDE is adding something extra in the background. I don't have any problems running pytest from the CLI. Second time this week that PyCharm bit me in the ass -- and it's only Tuesday. :/ |
Hi, I seems this issue has regressed (at least for me). The output of statements run outside of I am running pytest 3.2.4 under Python 3.6.2. |
First, thanks for maintaining such a great testing framework. It rocks !
It looks like that capture is not resumed after using the
disabled()
context manager. The following example should help reproduce the problem.The problem is reproducible on Ubuntu 15.10 using either python 2.7 / python 3.5, with pytest 3.0.2 or pytest master.
The text was updated successfully, but these errors were encountered: