Browse files

Improved compatibility in admin_scripts tests

Environment keys/values need to use native strings on some
plateforms. Thanks anubhav joshi for detecting the issue and
helping shaping the patch.
  • Loading branch information...
1 parent b787ef2 commit 8d7e048a8b428bebe82be735a84570f9250441e6 @claudep claudep committed Mar 8, 2014
Showing with 4 additions and 3 deletions.
  1. +4 −3 tests/admin_scripts/
@@ -24,7 +24,7 @@
from import BaseCommand, CommandError, call_command
from django.db import connection
from django.utils.encoding import force_text
-from django.utils._os import upath
+from django.utils._os import npath, upath
from django.utils.six import StringIO
from django.test import LiveServerTestCase, TestCase
from django.test.runner import DiscoverRunner
@@ -138,8 +138,9 @@ def run_test(self, script, args, settings_file=None, apps=None):
del test_environ['DJANGO_SETTINGS_MODULE']
python_path = [base_dir, django_dir, tests_dir]
- test_environ[python_path_var_name] = os.pathsep.join(python_path)
- test_environ['PYTHONWARNINGS'] = ''
+ # Use native strings for better compatibility
+ test_environ[str(python_path_var_name)] = npath(os.pathsep.join(python_path))
+ test_environ[str('PYTHONWARNINGS')] = str('')
# Move to the test directory and run

5 comments on commit 8d7e048


I'm still getting some errors (36 of them to be exact) on Windows, e.g.:

ERROR: test_builtin_with_bad_environment (admin_scripts.tests.ManageNoSettings)
no settings: builtin commands fail if settings file (from environment)
 doesn't exist
Traceback (most recent call last):
  File "c:\Users\Tim\django\tests\admin_scripts\", line 666, in test_bui
    out, err = self.run_manage(args, 'bad_settings')
  File "c:\Users\Tim\django\tests\admin_scripts\", line 180, in run_mana
    return self.run_test('./', args, settings_file)
  File "c:\Users\Tim\django\tests\admin_scripts\", line 149, in run_test

    env=test_environ, universal_newlines=True).communicate()
  File "c:\Python27\lib\", line 709, in __init__
    errread, errwrite)
  File "c:\Python27\lib\", line 957, in _execute_child
TypeError: environment can only contain strings

Is it a known issue or is it just me? \cc @coder9042


Tim, just before subprocess.Popen, try to print the environment: [print(key, type(key), type(val)) for key, val in test_environ.items()]. Then we can see which item contains unicode.


This fixes the issue (tested on Linux and Windows): Look ok?


Looks fine, feel free to commit.


Done in c4f772e,

Please sign in to comment.