diff --git a/src/_pytest/capture.py b/src/_pytest/capture.py index c4099e6b0..56707822d 100644 --- a/src/_pytest/capture.py +++ b/src/_pytest/capture.py @@ -12,6 +12,7 @@ from tempfile import TemporaryFile import pytest from _pytest.compat import CaptureIO +from _pytest.fixtures import FixtureRequest patchsysdict = {0: "stdin", 1: "stdout", 2: "stderr"} @@ -241,13 +242,12 @@ class CaptureManager: capture_fixtures = {"capfd", "capfdbinary", "capsys", "capsysbinary"} -def _ensure_only_one_capture_fixture(request, name): - fixtures = set(request.fixturenames) & capture_fixtures - {name} +def _ensure_only_one_capture_fixture(request: FixtureRequest, name): + fixtures = sorted(set(request.fixturenames) & capture_fixtures - {name}) if fixtures: - fixtures = sorted(fixtures) - fixtures = fixtures[0] if len(fixtures) == 1 else fixtures + arg = fixtures[0] if len(fixtures) == 1 else fixtures raise request.raiseerror( - "cannot use {} and {} at the same time".format(fixtures, name) + "cannot use {} and {} at the same time".format(arg, name) ) diff --git a/testing/test_capture.py b/testing/test_capture.py index 0f7db4b8e..180637db6 100644 --- a/testing/test_capture.py +++ b/testing/test_capture.py @@ -6,6 +6,8 @@ import subprocess import sys import textwrap from io import UnsupportedOperation +from typing import List +from typing import TextIO import py @@ -857,8 +859,8 @@ def tmpfile(testdir): @needsosdup -def test_dupfile(tmpfile): - flist = [] +def test_dupfile(tmpfile) -> None: + flist = [] # type: List[TextIO] for i in range(5): nf = capture.safe_text_dupfile(tmpfile, "wb") assert nf != tmpfile