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

There doesn't seem to be a way to easily change capture state within a test #1182

Closed
demianbrecht opened this issue Nov 18, 2015 · 4 comments

Comments

@demianbrecht
Copy link
Contributor

I might be missing something blatantly obvious, but it would be nice to be able to change the capture state at runtime. But first, a little context!

I have some code that fiddles with term settings. However, because capture uses a file-like object (that doesn't implement fileno), it will fail when twiddling bit flags. Trivial example:

import termios

def test_example():
    import sys

    termios.tcsetattr(
        sys.stdin, termios.TCSADRAIN, termios.tcgetattr(sys.stdin))

The above results in:

self = <_pytest.capture.DontReadFromInput instance at 0x102436440>

    def fileno(self):
>       raise ValueError("redirected Stdin is pseudofile, has no fileno()")
E       ValueError: redirected Stdin is pseudofile, has no fileno()

Of course, if you run pytest -s, all is wonderful. However, that's not an option in my case due to the drastic increase in log noise.

@codewarrior0
Copy link
Contributor

There are fixture functions capfd and capsys that allow you to enable capturing for a particular test, but there doesn't seem to be one for disabling it. I'd like to have one for disabling output capture - one of my tests relies on a subprocess having its stdio connected to a terminal (so it can verify that the subprocess sets its I/O encodings correctly).

@nicoddemus
Copy link
Member

Something like what's been discussed in #167?

@demianbrecht
Copy link
Contributor Author

@nicoddemus: Yep, looks like the solution to that would also solve this as well. I'll add a note to #167 and close this one.

@nicoddemus
Copy link
Member

Thanks @demianbrecht

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants