pytest-dev / pytest-dev/pytest

Invoking subprocess.check_output makes pytest fail under certain circumstances

Open
#10,693 3 comments 0 reactions 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

  • a detailed description of the bug or problem you are having

Invoking subprocess.check_output passing in sys.stderr as an argument to stderr within a test makes pytest fail if run with the --capture=sys or --capture=tee-sys options.

  • output of pip list from the virtual environment you are using
Package         Version
--------------- -------                                                                                                                                                                                                                                                                   attrs           22.2.0
exceptiongroup  1.1.0
iniconfig       2.0.0                                                                                                                                                                                                                                                                     packaging       23.0
pip             21.3.1                                                                                                                                                                                                                                                                    pluggy          1.0.0
py              1.11.0
pytest          7.2.0                                                                                                                                                                                                                                                                     pytest-html     3.2.0
pytest-metadata 2.0.4
pytest-timeout  2.1.0
setuptools      59.6.0
tomli           2.0.1
  • pytest and operating system versions

pytest 7.2.0
Fedora Workstation 36

  • minimal example if possible
import subprocess
import sys
def test_something():
    print("This gets printed")
    subprocess.check_output(["echo", "hello"], stderr=sys.stderr)
    print("This does not")

When running the file with pytest:

pytest test_itdoesntreallymatter.py --capture=tee-sys --html somepaththatiwant.html --self-contained-html

This generates an UnsupportedOperation exception.

FAILED test_itdoesntreallymatter.py::test_something - io.UnsupportedOperation: fileno

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 by running the minimal test with pytest 7.2.0 using --capture=sys or --capture=tee-sys and observe the io.UnsupportedOperation: fileno failure. Trace the capture behavior when subprocess.check_output receives sys.stderr. Done means the test completes without the exception and the later print remains handled correctly.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.