|
1 | 1 | # Copyright (c) Microsoft Corporation. All rights reserved. |
2 | 2 | # Licensed under the MIT License. |
| 3 | +from __future__ import print_function |
3 | 4 |
|
| 5 | +try: |
| 6 | + from io import StringIO |
| 7 | +except ImportError: # 2.7 |
| 8 | + from StringIO import StringIO |
4 | 9 | import os |
5 | 10 | import os.path |
| 11 | +import sys |
6 | 12 | import unittest |
7 | 13 |
|
8 | 14 | from ...util import Stub, StubProxy |
@@ -194,7 +200,6 @@ def test_unsupported_command(self): |
194 | 200 | class DiscoverTests(unittest.TestCase): |
195 | 201 |
|
196 | 202 | DEFAULT_ARGS = [ |
197 | | - '-pno:terminal', |
198 | 203 | '--collect-only', |
199 | 204 | ] |
200 | 205 |
|
@@ -231,6 +236,64 @@ def test_failure(self): |
231 | 236 | 'plugins': [plugin]}), |
232 | 237 | ]) |
233 | 238 |
|
| 239 | + def test_stdio_hidden(self): |
| 240 | + pytest_stdout = 'spamspamspamspamspamspamspammityspam' |
| 241 | + stub = Stub() |
| 242 | + def fake_pytest_main(args, plugins): |
| 243 | + stub.add_call('pytest.main', None, {'args': args, |
| 244 | + 'plugins': plugins}) |
| 245 | + print(pytest_stdout, end='') |
| 246 | + return 0 |
| 247 | + plugin = StubPlugin(stub) |
| 248 | + plugin.discovered = [] |
| 249 | + buf = StringIO() |
| 250 | + |
| 251 | + sys.stdout = buf |
| 252 | + try: |
| 253 | + discover([], hidestdio=True, |
| 254 | + _pytest_main=fake_pytest_main, _plugin=plugin) |
| 255 | + finally: |
| 256 | + sys.stdout = sys.__stdout__ |
| 257 | + captured = buf.getvalue() |
| 258 | + |
| 259 | + self.assertEqual(captured, '') |
| 260 | + self.assertEqual(stub.calls, [ |
| 261 | + ('pytest.main', None, {'args': self.DEFAULT_ARGS, |
| 262 | + 'plugins': [plugin]}), |
| 263 | + ('discovered.parents', None, None), |
| 264 | + ('discovered.__len__', None, None), |
| 265 | + ('discovered.__getitem__', (0,), None), |
| 266 | + ]) |
| 267 | + |
| 268 | + def test_stdio_not_hidden(self): |
| 269 | + pytest_stdout = 'spamspamspamspamspamspamspammityspam' |
| 270 | + stub = Stub() |
| 271 | + def fake_pytest_main(args, plugins): |
| 272 | + stub.add_call('pytest.main', None, {'args': args, |
| 273 | + 'plugins': plugins}) |
| 274 | + print(pytest_stdout, end='') |
| 275 | + return 0 |
| 276 | + plugin = StubPlugin(stub) |
| 277 | + plugin.discovered = [] |
| 278 | + buf = StringIO() |
| 279 | + |
| 280 | + sys.stdout = buf |
| 281 | + try: |
| 282 | + discover([], hidestdio=False, |
| 283 | + _pytest_main=fake_pytest_main, _plugin=plugin) |
| 284 | + finally: |
| 285 | + sys.stdout = sys.__stdout__ |
| 286 | + captured = buf.getvalue() |
| 287 | + |
| 288 | + self.assertEqual(captured, pytest_stdout) |
| 289 | + self.assertEqual(stub.calls, [ |
| 290 | + ('pytest.main', None, {'args': self.DEFAULT_ARGS, |
| 291 | + 'plugins': [plugin]}), |
| 292 | + ('discovered.parents', None, None), |
| 293 | + ('discovered.__len__', None, None), |
| 294 | + ('discovered.__getitem__', (0,), None), |
| 295 | + ]) |
| 296 | + |
234 | 297 |
|
235 | 298 | class CollectorTests(unittest.TestCase): |
236 | 299 |
|
@@ -301,7 +364,7 @@ def test_modifyitems(self): |
301 | 364 | # ignored (pytest-supported) |
302 | 365 | 'parameterize', 'usefixtures', 'filterwarnings', |
303 | 366 | # ignored (custom) |
304 | | - 'timeout', |
| 367 | + 'timeout', |
305 | 368 | ]], |
306 | 369 | ), |
307 | 370 | ]) |
|
0 commit comments