A possible fix for https://github.com/txels/ddt/issues/19
This commit is contained in:
16
ddt.py
16
ddt.py
@@ -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:
|
||||||
|
|||||||
@@ -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).
|
||||||
|
|||||||
@@ -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__'))
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user