|
1
|
|
|
import os, sys, subprocess |
|
2
|
|
|
|
|
3
|
|
|
here = os.path.dirname(os.path.abspath(__file__)) |
|
4
|
|
|
|
|
5
|
|
|
verbose_file = os.path.join(here, "verbose.py") |
|
6
|
|
|
non_verbose_file = os.path.join(here, "non_verbose.py") |
|
7
|
|
|
|
|
8
|
|
|
|
|
9
|
|
|
def _run_subprocess(script): |
|
10
|
|
|
output = [] |
|
11
|
|
|
process = subprocess.Popen( |
|
12
|
|
|
[sys.executable, "-u", script], |
|
13
|
|
|
stdout=subprocess.PIPE, |
|
14
|
|
|
stderr=subprocess.PIPE, |
|
15
|
|
|
text=True, |
|
16
|
|
|
bufsize=1, # Line buffered |
|
17
|
|
|
env={**os.environ, "PYTHONUNBUFFERED": "1"}, |
|
18
|
|
|
) |
|
19
|
|
|
# Read output line by line |
|
20
|
|
|
while True: |
|
21
|
|
|
line = process.stdout.readline() |
|
22
|
|
|
if line: |
|
23
|
|
|
output.append(line) |
|
24
|
|
|
if not line and process.poll() is not None: |
|
25
|
|
|
break |
|
26
|
|
|
|
|
27
|
|
|
return "".join(output), process.stderr.read() |
|
28
|
|
|
|
|
29
|
|
|
|
|
30
|
|
|
def test_empty_output(): |
|
31
|
|
|
stdout_verb, stderr_verb = _run_subprocess(verbose_file) |
|
32
|
|
|
stdout_non_verb, stderr_non_verb = _run_subprocess(non_verbose_file) |
|
33
|
|
|
|
|
34
|
|
|
print("\n stdout_verb \n", stdout_verb, "\n") |
|
35
|
|
|
print("\n stderr_verb \n", stderr_verb, "\n") |
|
36
|
|
|
|
|
37
|
|
|
print("\n stdout_non_verb \n", stdout_non_verb, "\n") |
|
38
|
|
|
print("\n stderr_non_verb \n", stderr_non_verb, "\n") |
|
39
|
|
|
|
|
40
|
|
|
assert "Results:" in stdout_verb |
|
41
|
|
|
assert not stdout_non_verb |
|
42
|
|
|
|