#1478 Added --show-capture=both option (fix comments)
This commit is contained in:
		
							parent
							
								
									1a650a9eb9
								
							
						
					
					
						commit
						71367881ed
					
				|  | @ -44,8 +44,9 @@ def pytest_addoption(parser): | ||||||
|                      help="traceback print mode (auto/long/short/line/native/no).") |                      help="traceback print mode (auto/long/short/line/native/no).") | ||||||
|     group._addoption('--show-capture', |     group._addoption('--show-capture', | ||||||
|                      action="store", dest="showcapture", |                      action="store", dest="showcapture", | ||||||
|                      choices=['no', 'stdout', 'stderr'], |                      choices=['no', 'stdout', 'stderr', 'both'], default='both', | ||||||
|                      help="Print only stdout/stderr on not print both.") |                      help="Controls how captured stdout/stderr is shown on failed tests. " | ||||||
|  |                           "Default is 'both'.") | ||||||
|     group._addoption('--fulltrace', '--full-trace', |     group._addoption('--fulltrace', '--full-trace', | ||||||
|                      action="store_true", default=False, |                      action="store_true", default=False, | ||||||
|                      help="don't cut any tracebacks (default is to cut).") |                      help="don't cut any tracebacks (default is to cut).") | ||||||
|  | @ -629,7 +630,9 @@ class TerminalReporter: | ||||||
|         if self.config.option.showcapture == 'no': |         if self.config.option.showcapture == 'no': | ||||||
|             return |             return | ||||||
|         for secname, content in rep.sections: |         for secname, content in rep.sections: | ||||||
|             if self.config.option.showcapture and not (self.config.option.showcapture in secname): |             print(self.config.option.showcapture) | ||||||
|  |             if self.config.option.showcapture != 'both': | ||||||
|  |                 if not (self.config.option.showcapture in secname): | ||||||
|                     continue |                     continue | ||||||
|             self._tw.sep("-", secname) |             self._tw.sep("-", secname) | ||||||
|             if content[-1:] == "\n": |             if content[-1:] == "\n": | ||||||
|  |  | ||||||
|  | @ -1,4 +1 @@ | ||||||
| Added `--show-capture` feature. You can choose 'no', 'stdout' or 'stderr' option. | New ``--show-capture`` command-line option that allows to specify how to display captured output when tests fail: ``no``, ``stdout``, ``stderr`` or ``both`` (the default). | ||||||
| 'no': stdout and stderr will now shown |  | ||||||
| 'stdout': stdout will shown in terminal if you use this option but stderr will not shown. |  | ||||||
| 'stderr': stderr will shown in terminal if you use this option but stdout will not shown. |  | ||||||
|  | @ -836,6 +836,10 @@ def pytest_report_header(config, startdir): | ||||||
|         result.stdout.fnmatch_lines(["!This is stdout!"]) |         result.stdout.fnmatch_lines(["!This is stdout!"]) | ||||||
|         result.stdout.fnmatch_lines(["!This is stderr!"]) |         result.stdout.fnmatch_lines(["!This is stderr!"]) | ||||||
| 
 | 
 | ||||||
|  |         result = testdir.runpytest("--show-capture=both", "--tb=short") | ||||||
|  |         result.stdout.fnmatch_lines(["!This is stdout!"]) | ||||||
|  |         result.stdout.fnmatch_lines(["!This is stderr!"]) | ||||||
|  | 
 | ||||||
|         result = testdir.runpytest("--show-capture=stdout", "--tb=short") |         result = testdir.runpytest("--show-capture=stdout", "--tb=short") | ||||||
|         assert "!This is stderr!" not in result.stdout.str() |         assert "!This is stderr!" not in result.stdout.str() | ||||||
|         assert "!This is stdout!" in result.stdout.str() |         assert "!This is stdout!" in result.stdout.str() | ||||||
|  | @ -844,6 +848,10 @@ def pytest_report_header(config, startdir): | ||||||
|         assert "!This is stdout!" not in result.stdout.str() |         assert "!This is stdout!" not in result.stdout.str() | ||||||
|         assert "!This is stderr!" in result.stdout.str() |         assert "!This is stderr!" in result.stdout.str() | ||||||
| 
 | 
 | ||||||
|  |         result = testdir.runpytest("--show-capture=no", "--tb=short") | ||||||
|  |         assert "!This is stdout!" not in result.stdout.str() | ||||||
|  |         assert "!This is stderr!" not in result.stdout.str() | ||||||
|  | 
 | ||||||
| 
 | 
 | ||||||
| @pytest.mark.xfail("not hasattr(os, 'dup')") | @pytest.mark.xfail("not hasattr(os, 'dup')") | ||||||
| def test_fdopen_kept_alive_issue124(testdir): | def test_fdopen_kept_alive_issue124(testdir): | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue