@@ -148,34 +148,6 @@ def read_global_capture(self):
148
148
149
149
# Fixture Control (it's just forwarding, think about removing this later)
150
150
151
- @contextlib .contextmanager
152
- def _capturing_for_request (
153
- self , request : FixtureRequest
154
- ) -> Generator ["CaptureFixture" , None , None ]:
155
- """
156
- Context manager that creates a ``CaptureFixture`` instance for the
157
- given ``request``, ensuring there is only a single one being requested.
158
-
159
- This is used has a helper with ``capsys``, ``capfd`` etc.
160
- """
161
- if self ._capture_fixture :
162
- other_name = next (
163
- k
164
- for k , v in map_fixname_class .items ()
165
- if v is self ._capture_fixture .captureclass
166
- )
167
- raise request .raiseerror (
168
- "cannot use {} and {} at the same time" .format (
169
- request .fixturename , other_name
170
- )
171
- )
172
- capture_class = map_fixname_class [request .fixturename ]
173
- self ._capture_fixture = CaptureFixture (capture_class , request )
174
- self .activate_fixture ()
175
- yield self ._capture_fixture
176
- self ._capture_fixture .close ()
177
- self ._capture_fixture = None
178
-
179
151
def activate_fixture (self ):
180
152
"""If the current item is using ``capsys`` or ``capfd``, activate them so they take precedence over
181
153
the global capture.
@@ -262,6 +234,36 @@ def pytest_internalerror(self, excinfo):
262
234
self .stop_global_capturing ()
263
235
264
236
237
+ @contextlib .contextmanager
238
+ def _capturing_for_request (
239
+ request : FixtureRequest ,
240
+ ) -> Generator ["CaptureFixture" , None , None ]:
241
+ """
242
+ Context manager that creates a ``CaptureFixture`` instance for the
243
+ given ``request``, ensuring there is only a single one being requested.
244
+
245
+ This is used has a helper with ``capsys``, ``capfd`` etc.
246
+ """
247
+ capman = request .config .pluginmanager .getplugin ("capturemanager" )
248
+ if capman ._capture_fixture :
249
+ other_name = next (
250
+ k
251
+ for k , v in map_fixname_class .items ()
252
+ if v is capman ._capture_fixture .captureclass
253
+ )
254
+ raise request .raiseerror (
255
+ "cannot use {} and {} at the same time" .format (
256
+ request .fixturename , other_name
257
+ )
258
+ )
259
+ capture_class = map_fixname_class [request .fixturename ]
260
+ capman ._capture_fixture = CaptureFixture (capture_class , request )
261
+ capman .activate_fixture ()
262
+ yield capman ._capture_fixture
263
+ capman ._capture_fixture .close ()
264
+ capman ._capture_fixture = None
265
+
266
+
265
267
@pytest .fixture
266
268
def capsys (request ):
267
269
"""Enable text capturing of writes to ``sys.stdout`` and ``sys.stderr``.
@@ -270,8 +272,7 @@ def capsys(request):
270
272
calls, which return a ``(out, err)`` namedtuple.
271
273
``out`` and ``err`` will be ``text`` objects.
272
274
"""
273
- capman = request .config .pluginmanager .getplugin ("capturemanager" )
274
- with capman ._capturing_for_request (request ) as fixture :
275
+ with _capturing_for_request (request ) as fixture :
275
276
yield fixture
276
277
277
278
@@ -283,8 +284,7 @@ def capsysbinary(request):
283
284
method calls, which return a ``(out, err)`` namedtuple.
284
285
``out`` and ``err`` will be ``bytes`` objects.
285
286
"""
286
- capman = request .config .pluginmanager .getplugin ("capturemanager" )
287
- with capman ._capturing_for_request (request ) as fixture :
287
+ with _capturing_for_request (request ) as fixture :
288
288
yield fixture
289
289
290
290
@@ -300,8 +300,7 @@ def capfd(request):
300
300
pytest .skip (
301
301
"capfd fixture needs os.dup function which is not available in this system"
302
302
)
303
- capman = request .config .pluginmanager .getplugin ("capturemanager" )
304
- with capman ._capturing_for_request (request ) as fixture :
303
+ with _capturing_for_request (request ) as fixture :
305
304
yield fixture
306
305
307
306
@@ -317,8 +316,7 @@ def capfdbinary(request):
317
316
pytest .skip (
318
317
"capfdbinary fixture needs os.dup function which is not available in this system"
319
318
)
320
- capman = request .config .pluginmanager .getplugin ("capturemanager" )
321
- with capman ._capturing_for_request (request ) as fixture :
319
+ with _capturing_for_request (request ) as fixture :
322
320
yield fixture
323
321
324
322
0 commit comments