Re: [Django] #34930: Parallel tests fail on Python 3.11+ and django 4.1.0+ when IsolatedAsyncioTestCase is used

61 views
Skip to first unread message

Django

unread,
Oct 27, 2023, 7:58:24 AM10/27/23
to django-...@googlegroups.com
#34930: Parallel tests fail on Python 3.11+ and django 4.1.0+ when
IsolatedAsyncioTestCase is used
-------------------------------------+-------------------------------------
Reporter: Matt Hegarty | Owner: nobody
Type: Bug | Status: closed
Component: Testing framework | Version: 4.2
Severity: Normal | Resolution: needsinfo
Keywords: pickle | Triage Stage:
_contextvars.Context _contextvars | Unreviewed
Context |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Natalia Bidart):

Replying to [comment:5 Matt Hegarty]:
> - The tests pass for me when running against `stable/4.0.x` (python
3.11) (i.e. no crash)
> - I have updated the
[https://github.com/matthewhegarty/tutorial/commit/640533b5703d93f30aa8a3fb96abcf5e3a3045be
test project] to see if you can reproduce

Thanks Matt for the extra details but it fails for me with `4.0.x`:

{{{
[~/fellowship/tutorial main|✚ 1…1]$ python -c "import django;
print(django.get_version())"
4.0.11

[~/fellowship/tutorial main|✚ 1…1]$ ./manage.py test --parallel
Found 4 test(s).
System check identified no issues (0 silenced).
Traceback (most recent call last):
File "/home/nessita/fellowship/tutorial/./manage.py", line 22, in
<module>
main()
File "/home/nessita/fellowship/tutorial/./manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "/home/nessita/.virtualenvs/djangodev/lib/python3.11/site-
packages/django/core/management/__init__.py", line 446, in
execute_from_command_line
utility.execute()
File "/home/nessita/.virtualenvs/djangodev/lib/python3.11/site-
packages/django/core/management/__init__.py", line 440, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/nessita/.virtualenvs/djangodev/lib/python3.11/site-
packages/django/core/management/commands/test.py", line 24, in
run_from_argv
super().run_from_argv(argv)
File "/home/nessita/.virtualenvs/djangodev/lib/python3.11/site-
packages/django/core/management/base.py", line 414, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/nessita/.virtualenvs/djangodev/lib/python3.11/site-
packages/django/core/management/base.py", line 460, in execute
output = self.handle(*args, **options)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/nessita/.virtualenvs/djangodev/lib/python3.11/site-
packages/django/core/management/commands/test.py", line 68, in handle
failures = test_runner.run_tests(test_labels)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/nessita/.virtualenvs/djangodev/lib/python3.11/site-
packages/django/test/runner.py", line 1006, in run_tests
result = self.run_suite(suite)
^^^^^^^^^^^^^^^^^^^^^
File "/home/nessita/.virtualenvs/djangodev/lib/python3.11/site-
packages/django/test/runner.py", line 930, in run_suite
return runner.run(suite)
^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/unittest/runner.py", line 217, in run
test(result)
File "/usr/lib/python3.11/unittest/suite.py", line 84, in __call__
return self.run(*args, **kwds)
^^^^^^^^^^^^^^^^^^^^^^^
File "/home/nessita/.virtualenvs/djangodev/lib/python3.11/site-
packages/django/test/runner.py", line 493, in run
subsuite_index, events = test_results.next(timeout=0.1)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/multiprocessing/pool.py", line 873, in next
raise value
File "/usr/lib/python3.11/multiprocessing/pool.py", line 540, in
_handle_tasks
put(task)
File "/usr/lib/python3.11/multiprocessing/connection.py", line 205, in
send
self._send_bytes(_ForkingPickler.dumps(obj))
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/multiprocessing/reduction.py", line 51, in
dumps
cls(buf, protocol).dump(obj)
TypeError: cannot pickle '_contextvars.Context' object
}}}

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

Django

unread,
Oct 27, 2023, 8:35:32 AM10/27/23
to django-...@googlegroups.com
#34930: Parallel tests fail on Python 3.11+ and django 4.1.0+ when
IsolatedAsyncioTestCase is used
-------------------------------------+-------------------------------------
Reporter: Matt Hegarty | Owner: nobody
Type: Bug | Status: closed
Component: Testing framework | Version: 4.2
Severity: Normal | Resolution: needsinfo
Keywords: pickle | Triage Stage:
_contextvars.Context _contextvars | Unreviewed
Context |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Matt Hegarty):

I wonder why it reports that there are 4 tests in your test run.

My output (Mac Ventura) using homebrew is below (tests pass). However, I
tried the same on my Ubuntu instance, and it failed with the same error
you got. Mariusz stated that homebrew is dodgy, so perhaps that's the
reason for the success.

I guess no need to spend any more time on it and we can leave it closed.

{{{
(tutorial-311) ➜ tutorial git:(main) ✗ python -c "import django;
print(django.get_version())"
4.0.11
(tutorial-311) ➜ tutorial git:(main) ✗ ./manage.py test --parallel
Found 2 test(s).


System check identified no issues (0 silenced).

..
----------------------------------------------------------------------
Ran 2 tests in 0.005s

OK
}}}

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

Django

unread,
Oct 27, 2023, 8:45:43 AM10/27/23
to django-...@googlegroups.com
#34930: Parallel tests fail on Python 3.11+ and django 4.1.0+ when
IsolatedAsyncioTestCase is used
-------------------------------------+-------------------------------------
Reporter: Matt Hegarty | Owner: nobody
Type: Bug | Status: closed
Component: Testing framework | Version: 4.2
Severity: Normal | Resolution: needsinfo
Keywords: pickle | Triage Stage:
_contextvars.Context _contextvars | Unreviewed
Context |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Matt Hegarty):

one final thought, the 'tutorial' test app passes when using python3.10 on
Ubuntu (any version of django) - it might be worth you confirming that is
the same for you.

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

Django

unread,
Oct 27, 2023, 10:06:17 AM10/27/23
to django-...@googlegroups.com
#34930: Parallel tests fail on Python 3.11+ and django 4.1.0+ when
IsolatedAsyncioTestCase is used
-------------------------------------+-------------------------------------
Reporter: Matt Hegarty | Owner: nobody
Type: Bug | Status: closed
Component: Testing framework | Version: 4.2
Severity: Normal | Resolution: needsinfo
Keywords: pickle | Triage Stage:
_contextvars.Context _contextvars | Unreviewed
Context |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Natalia Bidart):

* cc: Carlton Gibson, Mariusz Felisiak (added)


Comment:

I can confirm that the `./manage.py test --parallel` works with any
version of Django (4.0, 4.2, 5.0b1) and Python 3.10.

{{{
root@568680bc51ec:/tutorial# python --version
Python 3.10.13
root@568680bc51ec:/tutorial# python manage.py test --parallel


Found 2 test(s).
System check identified no issues (0 silenced).
..
----------------------------------------------------------------------

Ran 2 tests in 0.025s

OK
}}}

Given that this is an issue related to the Python version, I'm not sure
how to proceed. Mariusz, Carlton, what would be your advice in this case?

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

Django

unread,
Oct 27, 2023, 10:23:26 AM10/27/23
to django-...@googlegroups.com
#34930: Parallel tests fail on Python 3.11+ and django 4.1.0+ when
IsolatedAsyncioTestCase is used
-------------------------------------+-------------------------------------
Reporter: Matt Hegarty | Owner: nobody
Type: Bug | Status: closed
Component: Testing framework | Version: 4.2
Severity: Normal | Resolution: needsinfo
Keywords: pickle | Triage Stage:
_contextvars.Context _contextvars | Unreviewed
Context |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Carlton Gibson):

So the tests don't run in parallel on macOS prior to Django 4.1
([https://docs.djangoproject.com/en/4.2/releases/4.1/#tests release
notes]) so the whole pickle step never gets hit. I'd guess that would
explain the issue there.

> It seems that IsolatedAsyncioTestCase hasn't been (ever?) supported?

That's the nub of it.

Django's `SimpleTestCase` added equivalent support for `async def` test
methods in Django 3.1
([https://docs.djangoproject.com/en/4.2/topics/testing/tools/#testing-
asynchronous-code docs]), but `IsolatedAsyncioTestCase` wasn't part of
that.

This ticket is maybe a feature request to add support for
`IsolatedAsyncioTestCase` subclasses but what's the need, and given the
error…

{{{


TypeError: cannot pickle '_contextvars.Context' object
}}}

… is it going to be feasible at all?

(It might be but, for me, I'd like some indication of a yes there before
accepting such, so we don't send folks down a dead-end rabbit hole.)

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

Django

unread,
Oct 27, 2023, 10:44:39 AM10/27/23
to django-...@googlegroups.com
#34930: Parallel tests fail on Python 3.11+ and django 4.1.0+ when
IsolatedAsyncioTestCase is used
-------------------------------------+-------------------------------------
Reporter: Matt Hegarty | Owner: nobody
Type: Bug | Status: closed
Component: Testing framework | Version: 4.2
Severity: Normal | Resolution: needsinfo
Keywords: pickle | Triage Stage:
_contextvars.Context _contextvars | Unreviewed
Context |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Matt Hegarty):

Just to clarify, the tests pass with any version of Django if you use
python3.10 (tested on MacOS and Ubuntu). They fail when running 3.11 or
3.12.

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

Django

unread,
Oct 27, 2023, 11:49:43 AM10/27/23
to django-...@googlegroups.com
#34930: Parallel tests fail on Python 3.11+ and django 4.1.0+ when
IsolatedAsyncioTestCase is used
-------------------------------------+-------------------------------------
Reporter: Matt Hegarty | Owner: nobody
Type: Bug | Status: closed
Component: Testing framework | Version: 4.2
Severity: Normal | Resolution: needsinfo
Keywords: pickle | Triage Stage:
_contextvars.Context _contextvars | Unreviewed
Context |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Carlton Gibson):

Replying to [comment:12 Matt Hegarty]:


> Just to clarify, the tests pass with any version of Django if you use
python3.10 (tested on MacOS and Ubuntu). They fail when running 3.11 or
3.12.

I guess the question then is [https://docs.python.org/3/whatsnew/3.11.html
what change led to this in Python 3.11]?

The addition of `IsolatedAsyncioTestCase.enterAsyncContext()` is a
[https://docs.python.org/3/whatsnew/3.11.html#unittest likely candidate].

But, still, use of `IsolatedAsyncioTestCase` has never been supported by
Django, or tested in its test suite, so any success prior to 3.11 would be
coincidental (leveraging undefined behaviour from Django's point of view).
Adding such support would still be a new feature.

--
Ticket URL: <https://code.djangoproject.com/ticket/34930#comment:13>

Django

unread,
Oct 27, 2023, 11:53:22 AM10/27/23
to django-...@googlegroups.com
#34930: Parallel tests fail on Python 3.11+ and django 4.1.0+ when
IsolatedAsyncioTestCase is used
-------------------------------------+-------------------------------------
Reporter: Matt Hegarty | Owner: nobody
Type: Bug | Status: closed
Component: Testing framework | Version: 4.2
Severity: Normal | Resolution: needsinfo
Keywords: pickle | Triage Stage:
_contextvars.Context _contextvars | Unreviewed
Context |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Matt Hegarty):

OK. Thanks all for investigating.

--
Ticket URL: <https://code.djangoproject.com/ticket/34930#comment:14>

Django

unread,
Oct 27, 2023, 12:59:24 PM10/27/23
to django-...@googlegroups.com
#34930: Parallel tests fail on Python 3.11+ and django 4.1.0+ when
IsolatedAsyncioTestCase is used
-------------------------------------+-------------------------------------
Reporter: Matt Hegarty | Owner: nobody
Type: Bug | Status: closed
Component: Testing framework | Version: 4.2
Severity: Normal | Resolution: wontfix

Keywords: pickle | Triage Stage:
_contextvars.Context _contextvars | Unreviewed
Context |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Natalia Bidart):

* resolution: needsinfo => wontfix


Comment:

Setting to `wontfix` since that resolution aligns better with the latest
outcome. Thanks everyone!

--
Ticket URL: <https://code.djangoproject.com/ticket/34930#comment:15>

Reply all
Reply to author
Forward
0 new messages