Skip to content

Commit 491a068

Browse files
committed
Make subprocess tests resilient to warnings
1 parent 4f6621e commit 491a068

File tree

3 files changed

+25
-24
lines changed

3 files changed

+25
-24
lines changed

tests/test_dealloc.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def main():
4848

4949
cmd = sys.executable
5050
proc = await asyncio.create_subprocess_exec(
51-
cmd, b'-c', prog,
51+
cmd, b'-W', b'ignore', b'-c', prog,
5252
stdout=subprocess.PIPE,
5353
stderr=subprocess.PIPE,
5454
loop=self.loop)

tests/test_process.py

+19-18
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def test_process_preexec_fn_1(self):
7979
async def test():
8080
cmd = sys.executable
8181
proc = await asyncio.create_subprocess_exec(
82-
cmd, '-c',
82+
cmd, b'-W', b'ignore', '-c',
8383
'import os,sys;sys.stdout.write(os.getenv("FRUIT"))',
8484
stdout=subprocess.PIPE,
8585
preexec_fn=lambda: os.putenv("FRUIT", "apple"),
@@ -100,7 +100,7 @@ def raise_it():
100100
async def test():
101101
cmd = sys.executable
102102
proc = await asyncio.create_subprocess_exec(
103-
cmd, '-c', 'import time; time.sleep(10)',
103+
cmd, b'-W', b'ignore', '-c', 'import time; time.sleep(10)',
104104
preexec_fn=raise_it,
105105
loop=self.loop)
106106

@@ -126,7 +126,7 @@ async def test():
126126
def test_process_executable_1(self):
127127
async def test():
128128
proc = await asyncio.create_subprocess_exec(
129-
b'doesnotexist', b'-c', b'print("spam")',
129+
b'doesnotexist', b'-W', b'ignore', b'-c', b'print("spam")',
130130
executable=sys.executable,
131131
stdout=subprocess.PIPE,
132132
loop=self.loop)
@@ -145,7 +145,7 @@ async def test():
145145

146146
cmd = sys.executable
147147
proc = await asyncio.create_subprocess_exec(
148-
cmd, b'-c', prog,
148+
cmd, b'-W', b'ignore', b'-c', prog,
149149
stdin=subprocess.PIPE,
150150
stdout=subprocess.PIPE,
151151
loop=self.loop)
@@ -177,7 +177,7 @@ def handler(signum, frame):
177177

178178
cmd = sys.executable
179179
proc = await asyncio.create_subprocess_exec(
180-
cmd, b'-c', prog,
180+
cmd, b'-W', b'ignore', b'-c', prog,
181181
stdin=subprocess.PIPE,
182182
stdout=subprocess.PIPE,
183183
stderr=subprocess.PIPE,
@@ -216,7 +216,7 @@ async def test():
216216

217217
cmd = sys.executable
218218
proc = await asyncio.create_subprocess_exec(
219-
cmd, b'-c', prog,
219+
cmd, b'-W', b'ignore', b'-c', prog,
220220
stdin=subprocess.PIPE,
221221
stdout=subprocess.PIPE,
222222
stderr=subprocess.PIPE,
@@ -260,7 +260,7 @@ async def test():
260260
'''
261261

262262
proc = await asyncio.create_subprocess_exec(
263-
sys.executable, '-c', prog,
263+
sys.executable, b'-W', b'ignore', b'-c', prog,
264264
stdout=subprocess.PIPE,
265265
stderr=subprocess.STDOUT,
266266
loop=self.loop)
@@ -280,7 +280,7 @@ async def test():
280280
'''
281281

282282
proc = await asyncio.create_subprocess_exec(
283-
sys.executable, '-c', prog,
283+
sys.executable, b'-W', b'ignore', b'-c', prog,
284284
stdin=subprocess.DEVNULL,
285285
stdout=subprocess.DEVNULL,
286286
stderr=subprocess.DEVNULL,
@@ -316,7 +316,7 @@ async def test():
316316
tempfile.TemporaryFile() as non_inherited:
317317

318318
proc = await asyncio.create_subprocess_exec(
319-
sys.executable, '-c', prog, '--',
319+
sys.executable, b'-W', b'ignore', b'-c', prog, '--',
320320
str(inherited.fileno()),
321321
str(non_inherited.fileno()),
322322
stdout=subprocess.PIPE,
@@ -334,17 +334,18 @@ async def test():
334334
class _AsyncioTests:
335335

336336
# Program blocking
337-
PROGRAM_BLOCKED = [sys.executable, '-c', 'import time; time.sleep(3600)']
337+
PROGRAM_BLOCKED = [sys.executable, b'-W', b'ignore',
338+
b'-c', b'import time; time.sleep(3600)']
338339

339340
# Program copying input to output
340341
PROGRAM_CAT = [
341-
sys.executable, '-c',
342-
';'.join(('import sys',
343-
'data = sys.stdin.buffer.read()',
344-
'sys.stdout.buffer.write(data)'))]
342+
sys.executable, b'-c',
343+
b';'.join((b'import sys',
344+
b'data = sys.stdin.buffer.read()',
345+
b'sys.stdout.buffer.write(data)'))]
345346

346347
PROGRAM_ERROR = [
347-
sys.executable, '-c', '1/0'
348+
sys.executable, b'-W', b'ignore', b'-c', b'1/0'
348349
]
349350

350351
def test_stdin_not_inheritable(self):
@@ -354,7 +355,7 @@ def test_stdin_not_inheritable(self):
354355
def len_message(message):
355356
code = 'import sys; data = sys.stdin.read(); print(len(data))'
356357
proc = yield from asyncio.create_subprocess_exec(
357-
sys.executable, '-c', code,
358+
sys.executable, b'-W', b'ignore', b'-c', code,
358359
stdin=asyncio.subprocess.PIPE,
359360
stdout=asyncio.subprocess.PIPE,
360361
stderr=asyncio.subprocess.PIPE,
@@ -499,7 +500,7 @@ def test_terminate(self):
499500

500501
def test_send_signal(self):
501502
code = 'import time; print("sleeping", flush=True); time.sleep(3600)'
502-
args = [sys.executable, '-c', code]
503+
args = [sys.executable, b'-W', b'ignore', b'-c', code]
503504
create = asyncio.create_subprocess_exec(*args,
504505
stdout=subprocess.PIPE,
505506
loop=self.loop)
@@ -629,7 +630,7 @@ async def test():
629630
'''
630631

631632
proc = await asyncio.create_subprocess_exec(
632-
sys.executable, '-c', prog,
633+
sys.executable, b'-W', b'ignore', b'-c', prog,
633634
loop=self.loop)
634635

635636
out, err = await proc.communicate()

tests/test_signals.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def run():
4040
"""
4141

4242
proc = await asyncio.create_subprocess_exec(
43-
sys.executable, b'-c', PROG,
43+
sys.executable, b'-W', b'ignore', b'-c', PROG,
4444
stdout=subprocess.PIPE,
4545
stderr=subprocess.PIPE,
4646
loop=self.loop)
@@ -86,7 +86,7 @@ def run():
8686
"""
8787

8888
proc = await asyncio.create_subprocess_exec(
89-
sys.executable, b'-c', PROG,
89+
sys.executable, b'-W', b'ignore', b'-c', PROG,
9090
stdout=subprocess.PIPE,
9191
stderr=subprocess.PIPE,
9292
loop=self.loop)
@@ -127,7 +127,7 @@ async def worker():
127127
"""
128128

129129
proc = await asyncio.create_subprocess_exec(
130-
sys.executable, b'-c', PROG,
130+
sys.executable, b'-W', b'ignore', b'-c', PROG,
131131
stdout=subprocess.PIPE,
132132
stderr=subprocess.PIPE,
133133
loop=self.loop)
@@ -177,7 +177,7 @@ def handler_hup(say):
177177
"""
178178

179179
proc = await asyncio.create_subprocess_exec(
180-
sys.executable, b'-c', PROG,
180+
sys.executable, b'-W', b'ignore', b'-c', PROG,
181181
stdout=subprocess.PIPE,
182182
stderr=subprocess.PIPE,
183183
loop=self.loop)
@@ -236,7 +236,7 @@ def handler_hup():
236236
"""
237237

238238
proc = await asyncio.create_subprocess_exec(
239-
sys.executable, b'-c', PROG,
239+
sys.executable, b'-W', b'ignore', b'-c', PROG,
240240
stdout=subprocess.PIPE,
241241
stderr=subprocess.PIPE,
242242
loop=self.loop)

0 commit comments

Comments
 (0)