[Django] #31407: "RuntimeWarning: coroutine 'sleep' was never awaited" observed when running tests with Python 3.7 and Python 3.8

205 views
Skip to first unread message

Django

unread,
Mar 29, 2020, 7:11:58 AM3/29/20
to django-...@googlegroups.com
#31407: "RuntimeWarning: coroutine 'sleep' was never awaited" observed when running
tests with Python 3.7 and Python 3.8
---------------------------------------------+------------------------
Reporter: Deep Sukhwani | Owner: nobody
Type: Bug | Status: new
Component: Testing framework | Version: 3.0
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
---------------------------------------------+------------------------
**Steps to reproduce:**
- Use a Python virtualenv with Python 3.7.7 / Python 3.8.2
- Install requirements - from Django root with latest master (of the the
date of this issue): `cd tests && pip install -r requirements/py3.txt`
- Run tests `export DJANGO_TEST_PROCESSES=1; export
OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES; ./runtests.py`
- This is reproducible in django-docker-box using Python 3.7 and Python
3.8, verified as follows:
`PYTHON_VERSION=3.7 docker-compose run --rm sqlite`
`PYTHON_VERSION=3.8 docker-compose run --rm sqlite`

**Notes:**
- To ensure this is not happening due to parallelization, I had set
`export DJANGO_TEST_PROCESSES=1;` while triggering `./runtests.py`

**Warning text:**
{{{
Exception ignored in: <coroutine object sleep at 0x130ef1320>
Traceback (most recent call last):
File "/Users/ds/.pyenv/versions/3.7.7/lib/python3.7/warnings.py", line
518, in _warn_unawaited_coroutine
warn(msg, category=RuntimeWarning, stacklevel=2, source=coro)
RuntimeWarning: coroutine 'sleep' was never awaited
}}}


**Other Observations:**
- This warning was not observed when running tests with Python 3.6,
verified on macOS and django-docker-box. For `django-docker-box` the tests
were run using: `PYTHON_VERSION=3.6 docker-compose run --rm sqlite`

--
Ticket URL: <https://code.djangoproject.com/ticket/31407>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Mar 30, 2020, 1:04:44 AM3/30/20
to django-...@googlegroups.com
#31407: RuntimeWarning when running
AsyncHandlerRequestTests.test_unawaited_response.
--------------------------------------+------------------------------------

Reporter: Deep Sukhwani | Owner: nobody
Type: Cleanup/optimization | Status: new

Component: Testing framework | Version: 3.0
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by felixxm):

* type: Bug => Cleanup/optimization
* easy: 0 => 1
* stage: Unreviewed => Accepted


Comment:

`handlers.tests.AsyncHandlerRequestTests.test_unawaited_response` raises
this warning because it tests unawaited coroutine. I agree that we can
suppress this warning.

--
Ticket URL: <https://code.djangoproject.com/ticket/31407#comment:1>

Django

unread,
Mar 30, 2020, 1:41:50 PM3/30/20
to django-...@googlegroups.com
#31407: RuntimeWarning when running
AsyncHandlerRequestTests.test_unawaited_response.
-------------------------------------+-------------------------------------
Reporter: Deep Sukhwani | Owner: Rafael
Type: | Arellano
Cleanup/optimization | Status: assigned

Component: Testing framework | Version: 3.0
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Rafael Arellano):

* owner: nobody => Rafael Arellano
* status: new => assigned


--
Ticket URL: <https://code.djangoproject.com/ticket/31407#comment:2>

Django

unread,
Mar 31, 2020, 12:13:58 PM3/31/20
to django-...@googlegroups.com
#31407: RuntimeWarning when running
AsyncHandlerRequestTests.test_unawaited_response.
--------------------------------------+------------------------------------
Reporter: Deep Sukhwani | Owner: (none)
Type: Cleanup/optimization | Status: new

Component: Testing framework | Version: 3.0
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by Rafael Arellano):

* owner: Rafael Arellano => (none)
* status: assigned => new


--
Ticket URL: <https://code.djangoproject.com/ticket/31407#comment:3>

Django

unread,
Apr 1, 2020, 8:12:00 PM4/1/20
to django-...@googlegroups.com
#31407: RuntimeWarning when running
AsyncHandlerRequestTests.test_unawaited_response.
-------------------------------------+-------------------------------------
Reporter: Deep Sukhwani | Owner:
Type: | MSadeghzadehG
Cleanup/optimization | Status: assigned

Component: Testing framework | Version: 3.0
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by MSadeghzadehG):

* owner: nobody => MSadeghzadehG


* status: new => assigned


--
Ticket URL: <https://code.djangoproject.com/ticket/31407#comment:2>

Django

unread,
Apr 3, 2020, 7:05:43 AM4/3/20
to django-...@googlegroups.com
#31407: RuntimeWarning when running
AsyncHandlerRequestTests.test_unawaited_response.
-------------------------------------+-------------------------------------
Reporter: Deep Sukhwani | Owner: Mahdi
Type: | Sadeghzadeh Ghamsary
Cleanup/optimization | Status: assigned

Component: Testing framework | Version: 3.0
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Mark):

Replying to [comment:2 Mahdi Sadeghzadeh Ghamsary]:


How are you going with this? Otherwise I would gladly take a shot a this

--
Ticket URL: <https://code.djangoproject.com/ticket/31407#comment:3>

Django

unread,
Apr 4, 2020, 2:27:28 PM4/4/20
to django-...@googlegroups.com
#31407: RuntimeWarning when running
AsyncHandlerRequestTests.test_unawaited_response.
--------------------------------------+------------------------------------
Reporter: Deep Sukhwani | Owner: Mark
Type: Cleanup/optimization | Status: assigned

Component: Testing framework | Version: 3.0
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by Mark):

* owner: Mahdi Sadeghzadeh Ghamsary => Mark


--
Ticket URL: <https://code.djangoproject.com/ticket/31407#comment:4>

Django

unread,
Apr 4, 2020, 2:36:36 PM4/4/20
to django-...@googlegroups.com
#31407: RuntimeWarning when running
AsyncHandlerRequestTests.test_unawaited_response.
--------------------------------------+------------------------------------
Reporter: Deep Sukhwani | Owner: Mark
Type: Cleanup/optimization | Status: assigned
Component: Testing framework | Version: 3.0
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by Mark):

* has_patch: 0 => 1


Comment:

[https://github.com/django/django/pull/12661 PR]

--
Ticket URL: <https://code.djangoproject.com/ticket/31407#comment:5>

Django

unread,
Apr 7, 2020, 2:33:12 PM4/7/20
to django-...@googlegroups.com
#31407: RuntimeWarning when running
AsyncHandlerRequestTests.test_unawaited_response.
--------------------------------------+------------------------------------
Reporter: Deep Sukhwani | Owner: Mark
Type: Cleanup/optimization | Status: closed

Component: Testing framework | Version: 3.0
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by GitHub <noreply@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"590957a0eb9a87a6f2bd3463226b0a7f1405d817" 590957a]:
{{{
#!CommitTicketReference repository=""
revision="590957a0eb9a87a6f2bd3463226b0a7f1405d817"
Fixed #31407 -- Adjusted test to avoid coroutine never awaited warning.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/31407#comment:6>

Django

unread,
Apr 9, 2020, 4:51:16 AM4/9/20
to django-...@googlegroups.com
#31407: RuntimeWarning when running
AsyncHandlerRequestTests.test_unawaited_response.
--------------------------------------+------------------------------------
Reporter: Deep Sukhwani | Owner: Mark
Type: Cleanup/optimization | Status: new

Component: Testing framework | Version: 3.0
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by felixxm):

* status: closed => new
* has_patch: 1 => 0
* resolution: fixed =>


Comment:

With this fix we have the same warning but after all tests, e.g.
{{{
./runtests.py handlers --parallel=1

Testing against Django installed in 'django/django'
Creating test database for alias 'default'...
System check identified no issues (0 silenced).
.............................
----------------------------------------------------------------------
Ran 29 tests in 0.377s

OK
Destroying test database for alias 'default'...
Exception ignored in: <coroutine object sleep at 0x7fc660d70040>


RuntimeWarning: coroutine 'sleep' was never awaited
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/31407#comment:7>

Django

unread,
Apr 9, 2020, 4:52:44 AM4/9/20
to django-...@googlegroups.com
#31407: RuntimeWarning when running
AsyncHandlerRequestTests.test_unawaited_response.
-------------------------------------+-------------------------------------
Reporter: Deep Sukhwani | Owner: Carlton
Type: | Gibson
Cleanup/optimization | Status: assigned

Component: Testing framework | Version: 3.0
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Carlton Gibson):

* owner: Mark => Carlton Gibson


* status: new => assigned


Comment:

OK, I will take another look. (I had this clearing up OK the other day
so...) Thanks Mariusz.

--
Ticket URL: <https://code.djangoproject.com/ticket/31407#comment:8>

Django

unread,
Apr 9, 2020, 5:55:18 AM4/9/20
to django-...@googlegroups.com
#31407: RuntimeWarning when running
AsyncHandlerRequestTests.test_unawaited_response.
-------------------------------------+-------------------------------------
Reporter: Deep Sukhwani | Owner: Carlton
Type: | Gibson
Cleanup/optimization | Status: assigned
Component: Testing framework | Version: 3.0
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Carlton Gibson):

[https://github.com/django/django/pull/12691 New PR]

--
Ticket URL: <https://code.djangoproject.com/ticket/31407#comment:9>

Django

unread,
Apr 9, 2020, 6:04:03 AM4/9/20
to django-...@googlegroups.com
#31407: RuntimeWarning when running
AsyncHandlerRequestTests.test_unawaited_response.
-------------------------------------+-------------------------------------
Reporter: Deep Sukhwani | Owner: Carlton
Type: | Gibson
Cleanup/optimization | Status: assigned
Component: Testing framework | Version: 3.0
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by felixxm):

* has_patch: 0 => 1

* stage: Accepted => Ready for checkin


Comment:

[https://github.com/django/django/pull/12691 PR]

--
Ticket URL: <https://code.djangoproject.com/ticket/31407#comment:10>

Django

unread,
Apr 9, 2020, 6:35:32 AM4/9/20
to django-...@googlegroups.com
#31407: RuntimeWarning when running
AsyncHandlerRequestTests.test_unawaited_response.
-------------------------------------+-------------------------------------
Reporter: Deep Sukhwani | Owner: Carlton
Type: | Gibson
Cleanup/optimization | Status: closed

Component: Testing framework | Version: 3.0
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Carlton Gibson <carlton@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"ed274a4ae4665b5c7a367670b0c89c8eeed1c8b4" ed274a4a]:
{{{
#!CommitTicketReference repository=""
revision="ed274a4ae4665b5c7a367670b0c89c8eeed1c8b4"
Fixed #31407 -- Fixed unawaited coroutine warning for Python 3.8+.

Co-authored-by: Mark Korput <dr.t...@gmail.com>
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/31407#comment:11>

Django

unread,
Feb 15, 2022, 8:38:33 AM2/15/22
to django-...@googlegroups.com
#31407: RuntimeWarning when running
AsyncHandlerRequestTests.test_unawaited_response.
-------------------------------------+-------------------------------------
Reporter: Deep Sukhwani | Owner: Carlton
Type: | Gibson
Cleanup/optimization | Status: closed
Component: Testing framework | Version: 3.0
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Carlton Gibson <carlton@…>):

In [changeset:"236e6cb5881168a79a194b43c2d8dff7a14c3f03" 236e6cb5]:
{{{
#!CommitTicketReference repository=""
revision="236e6cb5881168a79a194b43c2d8dff7a14c3f03"
Refs #31407 -- Handled potential exception in test cleanup.

The test view may not be called when running the tests with
--parallel=2 or greater. Catch the AttributeError for this case.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/31407#comment:12>

Reply all
Reply to author
Forward
0 new messages