Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
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...
commit 8d7e048a8b428bebe82be735a84570f9250441e6 1 parent b787ef2
@claudep claudep authored
Showing with 4 additions and 3 deletions.
  1. +4 −3 tests/admin_scripts/tests.py
View
7 tests/admin_scripts/tests.py
@@ -24,7 +24,7 @@
from django.core.management 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]
python_path.extend(ext_backend_base_dirs)
- 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
os.chdir(test_dir)

5 comments on commit 8d7e048

@timgraham
Owner

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: manage.py builtin commands fail if settings file (from environment)
 doesn't exist
----------------------------------------------------------------------
Traceback (most recent call last):
  File "c:\Users\Tim\django\tests\admin_scripts\tests.py", line 666, in test_bui
ltin_with_bad_environment
    out, err = self.run_manage(args, 'bad_settings')
  File "c:\Users\Tim\django\tests\admin_scripts\tests.py", line 180, in run_mana
ge
    return self.run_test('./manage.py', args, settings_file)
  File "c:\Users\Tim\django\tests\admin_scripts\tests.py", line 149, in run_test

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

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

@claudep
Collaborator

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.

@timgraham
Owner

This fixes the issue (tested on Linux and Windows): http://dpaste.com/1714697/ Look ok?

@claudep
Collaborator

Looks fine, feel free to commit.

@timgraham
Owner

Done in c4f772e,

Please sign in to comment.
Something went wrong with that request. Please try again.