Change theme
Help
Press space for more information.
Show links for this issue (Shortcut: i, l)
Copy issue ID
Previous Issue (Shortcut: k)
Next Issue (Shortcut: j)
Sign in to use full features.
Vote: I am impacted
Notification menu
Refresh (Shortcut: Shift+r)
Go home (Shortcut: u)
Pending code changes (auto-populated)
View issue level access limits(Press Alt + Right arrow for more information)
Unintended behavior
View staffing
Description
File "/google-cloud-sdk/platform/google_appengine/lib/django-1.11/django/test/runner.py", line 288, in default_test_processes
return multiprocessing.cpu_count()
NameError: global name 'multiprocessing' is not defined
although I'm not using the --parallel option.
I've checked the django1.11 code that comes with the AppEngineSDK and the problem is the following: the import of the multiprocessing module is removed. The first lines of /google-cloud-sdk/platform/google_appengine/lib/django-1.11/django/test/runner.py are the following:
#import ctypes # Google: App Engine doesn't support ctypes
import itertools
import logging
#import multiprocessing # Google: Don't parallelize tests under App Engine
The problem with removing this import is that the function default_test_processes (in the same module) uses the multiprocessing module to detect the number of CPUs, here is the code
def default_test_processes():
"""
Default number of test processes when using the --parallel option.
"""
# The current implementation of the parallel test runner requires
# multiprocessing to start subprocesses with fork().
# On Python 3.4+: if multiprocessing.get_start_method() != 'fork':
if not hasattr(os, 'fork'):
return 1
try:
return int(os.environ['DJANGO_TEST_PROCESSES'])
except KeyError:
return multiprocessing.cpu_count()
This function is used in the method add_arguments of the class DiscoverRunner which is invoked every time you run
from django.core.management import execute_from_command_line
execute_from_command_line(["tests"])
As a workaround, I've set the env variable DJANGO_TEST_PROCESSES equal to "1"
Note that this problem happens in Linux and MacOS but not in Windows, because it doesn't have fork.