This commit is contained in:
Santeri Paavolainen
2014-05-21 12:29:33 +03:00
parent 5c00b6e844
commit 11fad53fbb
3 changed files with 34 additions and 1 deletions

16
ddt.py
View File

@@ -2,6 +2,7 @@ import inspect
import json import json
import os import os
import re import re
import sys
from functools import wraps from functools import wraps
__version__ = '0.8.0' __version__ = '0.8.0'
@@ -70,7 +71,22 @@ def mk_test_name(name, value, index=0):
string representation of the value, and convert the result into a valid string representation of the value, and convert the result into a valid
python identifier by replacing extraneous characters with ``_``. python identifier by replacing extraneous characters with ``_``.
If hash randomization is enabled (a feature available since 2.7.3
and enabled by default since 3.3) and a non-scalar value is passed
this will omit the name argument by default. Set `PYTHONHASHSEED`
to a fixed value before running tests in these cases to get the
names back consistently.
""" """
print(sys.flags)
if sys.hexversion >= 0x02070300 and \
sys.flags.hash_randomization and \
'PYTHONHASHSEED' not in os.environ and \
not isinstance(value, (type(None), str, int, float)):
return "{0}_{1}".format(name, index + 1)
try: try:
value = str(value) value = str(value)
except UnicodeEncodeError: except UnicodeEncodeError:

View File

@@ -42,3 +42,16 @@ multiplied.
DDT will try to give the new test cases meaningful names by converting the DDT will try to give the new test cases meaningful names by converting the
data values to valid python identifiers. data values to valid python identifiers.
.. note::
Python 2.7.3 introduced *hash randomization* which is by default
enabled on Python 3.3 and later. DDT's default mechanism to
generate meaningful test names will **not** use the test data value
as part of the name for complex types if hash randomization is
enabled.
You can disable hash randomization by setting the
``PYTHONHASHSEED`` environment variable to a fixed value before
running tests (``export PYTHONHASHSEED=1`` for example).

View File

@@ -1,5 +1,6 @@
import os import os
import json import json
import sys
import six import six
@@ -238,6 +239,9 @@ def test_ddt_data_unicode():
assert_is_not_none(getattr(mytest, 'test_hello_1_ascii')) assert_is_not_none(getattr(mytest, 'test_hello_1_ascii'))
assert_is_not_none(getattr(mytest, 'test_hello_2_non_ascii__')) assert_is_not_none(getattr(mytest, 'test_hello_2_non_ascii__'))
if sys.hexversion >= 0x03030300 and 'PYTHONHASHSEED' not in os.environ:
assert_is_not_none(getattr(mytest, 'test_hello_3'))
else:
assert_is_not_none(getattr(mytest, 'test_hello_3________data__')) assert_is_not_none(getattr(mytest, 'test_hello_3________data__'))