testdir.popen: use kwargs with defaults for stdout/stderr
This commit is contained in:
		
							parent
							
								
									9ad00714ba
								
							
						
					
					
						commit
						4fca86e2af
					
				|  | @ -0,0 +1 @@ | ||||||
|  | pytester's ``Testdir.popen()`` uses ``stdout`` and ``stderr`` via keyword arguments with defaults now (``subprocess.PIPE``). | ||||||
|  | @ -1034,7 +1034,14 @@ class Testdir(object): | ||||||
|             if colitem.name == name: |             if colitem.name == name: | ||||||
|                 return colitem |                 return colitem | ||||||
| 
 | 
 | ||||||
|     def popen(self, cmdargs, stdout, stderr, stdin=CLOSE_STDIN, **kw): |     def popen( | ||||||
|  |         self, | ||||||
|  |         cmdargs, | ||||||
|  |         stdout=subprocess.PIPE, | ||||||
|  |         stderr=subprocess.PIPE, | ||||||
|  |         stdin=CLOSE_STDIN, | ||||||
|  |         **kw | ||||||
|  |     ): | ||||||
|         """Invoke subprocess.Popen. |         """Invoke subprocess.Popen. | ||||||
| 
 | 
 | ||||||
|         This calls subprocess.Popen making sure the current working directory |         This calls subprocess.Popen making sure the current working directory | ||||||
|  |  | ||||||
|  | @ -540,3 +540,22 @@ def test_popen_stdin_bytes(testdir): | ||||||
|     assert stdout.decode("utf8").splitlines() == ["input", "2ndline"] |     assert stdout.decode("utf8").splitlines() == ["input", "2ndline"] | ||||||
|     assert stderr == b"" |     assert stderr == b"" | ||||||
|     assert proc.returncode == 0 |     assert proc.returncode == 0 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | def test_popen_default_stdin_stderr_and_stdin_None(testdir): | ||||||
|  |     # stdout, stderr default to pipes, | ||||||
|  |     # stdin can be None to not close the pipe, avoiding | ||||||
|  |     # "ValueError: flush of closed file" with `communicate()`. | ||||||
|  |     p1 = testdir.makepyfile( | ||||||
|  |         """ | ||||||
|  |         import sys | ||||||
|  |         print(sys.stdin.read())  # empty | ||||||
|  |         print('stdout') | ||||||
|  |         sys.stderr.write('stderr') | ||||||
|  |         """ | ||||||
|  |     ) | ||||||
|  |     proc = testdir.popen([sys.executable, str(p1)], stdin=None) | ||||||
|  |     stdout, stderr = proc.communicate(b"ignored") | ||||||
|  |     assert stdout.splitlines() == [b"", b"stdout"] | ||||||
|  |     assert stderr.splitlines() == [b"stderr"] | ||||||
|  |     assert proc.returncode == 0 | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue