Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c082ee6

Browse files
committed
asyncio: Add an unit test to check that setting the PYTHONASYNCIODEBUG env var
enables debug mode of the event loop.
1 parent 7b7120e commit c082ee6

2 files changed

Lines changed: 24 additions & 4 deletions

File tree

Lib/test/test_asyncio/test_base_events.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import time
88
import unittest
99
from unittest import mock
10+
from test.script_helper import assert_python_ok
1011
from test.support import IPV6_ENABLED
1112

1213
import asyncio
@@ -489,6 +490,29 @@ def custom_handler(loop, context):
489490
self.assertIs(type(_context['context']['exception']),
490491
ZeroDivisionError)
491492

493+
def test_env_var_debug(self):
494+
code = '\n'.join((
495+
'import asyncio',
496+
'loop = asyncio.get_event_loop()',
497+
'print(loop.get_debug())'))
498+
499+
# Test with -E to not fail if the unit test was run with
500+
# PYTHONASYNCIODEBUG set to a non-empty string
501+
sts, stdout, stderr = assert_python_ok('-E', '-c', code)
502+
self.assertEqual(stdout.rstrip(), b'False')
503+
504+
sts, stdout, stderr = assert_python_ok('-c', code,
505+
PYTHONASYNCIODEBUG='')
506+
self.assertEqual(stdout.rstrip(), b'False')
507+
508+
sts, stdout, stderr = assert_python_ok('-c', code,
509+
PYTHONASYNCIODEBUG='1')
510+
self.assertEqual(stdout.rstrip(), b'True')
511+
512+
sts, stdout, stderr = assert_python_ok('-E', '-c', code,
513+
PYTHONASYNCIODEBUG='1')
514+
self.assertEqual(stdout.rstrip(), b'False')
515+
492516

493517
class MyProto(asyncio.Protocol):
494518
done = None

Lib/test/test_asyncio/test_tasks.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1577,11 +1577,7 @@ def test_return_exceptions(self):
15771577
self.assertEqual(fut.result(), [3, 1, exc, exc2])
15781578

15791579
def test_env_var_debug(self):
1580-
path = os.path.dirname(asyncio.__file__)
1581-
path = os.path.normpath(os.path.join(path, '..'))
15821580
code = '\n'.join((
1583-
'import sys',
1584-
'sys.path.insert(0, %r)' % path,
15851581
'import asyncio.tasks',
15861582
'print(asyncio.tasks._DEBUG)'))
15871583

0 commit comments

Comments
 (0)