pytest-dev / pytest-dev/pytest

capsys.disabled for stdin

Open
#2,189 14 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

plugin: capture
Dominant language
Python
Stars
14.5k
Forks
3.4k
Avg merge
2d 9h
Merged PRs (30d)
35

Description

I'm using pytest 3.0.4

Currently, using capsys.disabled prevents the capturing on stdout. But it does not do anything for stdin, which is also important for my use. (specifically, I want to be able to use input().)

Adding the -s command line option works, but I'd like to do it programmatically in a test. Ideally, you'd get something like this:

    def test_capfd_thing(capfd):
        print("this won't be visible")
        with capsys.disabled():
            print("this will be visible.")
            s = input("Type the word potato:")
            print("you said: "+ s)
        assert 'potato' in s

I'm not sure whether only disabling the capturing of stdout is expected behavior (in which case I would like a way to do what I'm doing above) or a bug.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start from the capsys.disabled entry point and the -s command-line behavior described in the issue, then inspect the capture implementation and related tests. Verify how stdin is handled while stdout capture is disabled; done means a test can use input() interactively inside the context while normal capture remains unchanged outside it.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
testing
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.