Opened 5 years ago

Closed 5 years ago

Last modified 3 years ago

#31407 closed Cleanup/optimization (fixed)

RuntimeWarning when running AsyncHandlerRequestTests.test_unawaited_response.

Reported by: Deep Sukhwani Owned by: Carlton Gibson
Component: Testing framework Version: 3.0
Severity: Normal Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

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

Change History (12)

comment:1 by Mariusz Felisiak, 5 years ago

Easy pickings: set
Summary: "RuntimeWarning: coroutine 'sleep' was never awaited" observed when running tests with Python 3.7 and Python 3.8RuntimeWarning when running AsyncHandlerRequestTests.test_unawaited_response.
Triage Stage: UnreviewedAccepted
Type: BugCleanup/optimization

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

comment:2 by Mahdi Sadeghzadeh Ghamsary, 5 years ago

Owner: changed from nobody to Mahdi Sadeghzadeh Ghamsary
Status: newassigned

in reply to:  2 comment:3 by Mark, 5 years ago

Replying to Mahdi Sadeghzadeh Ghamsary:

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

comment:4 by Mark, 5 years ago

Owner: changed from Mahdi Sadeghzadeh Ghamsary to Mark

comment:5 by Mark, 5 years ago

Has patch: set

comment:6 by GitHub <noreply@…>, 5 years ago

Resolution: fixed
Status: assignedclosed

In 590957a:

Fixed #31407 -- Adjusted test to avoid coroutine never awaited warning.

comment:7 by Mariusz Felisiak, 5 years ago

Has patch: unset
Resolution: fixed
Status: closednew

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

comment:8 by Carlton Gibson, 5 years ago

Owner: changed from Mark to Carlton Gibson
Status: newassigned

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

comment:9 by Carlton Gibson, 5 years ago

comment:10 by Mariusz Felisiak, 5 years ago

Has patch: set
Triage Stage: AcceptedReady for checkin
Version 0, edited 5 years ago by Mariusz Felisiak (next)

comment:11 by Carlton Gibson <carlton@…>, 5 years ago

Resolution: fixed
Status: assignedclosed

In ed274a4a:

Fixed #31407 -- Fixed unawaited coroutine warning for Python 3.8+.

Co-authored-by: Mark Korput <dr.theman@…>

comment:12 by Carlton Gibson <carlton@…>, 3 years ago

In 236e6cb5:

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.

Note: See TracTickets for help on using tickets.
Back to Top