Skip to content

Commit 23a8e2b

Browse files
committed
Add .hypothesis to .gitignore and try an older version of Hypothesis for 2.6
2 parents 08671fc + fed89ef commit 23a8e2b

File tree

5 files changed

+26
-14
lines changed

5 files changed

+26
-14
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,4 @@ env/
3232
.coverage
3333
.ropeproject
3434
.idea
35+
.hypothesis

CHANGELOG.rst

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,11 @@
2929

3030
* parametrize ids can accept None as specific test id. The
3131
automatically generated id for that argument will be used.
32+
Thanks `@palaviv`_ for the complete PR (`#1468`_).
3233

33-
*
34+
* improved idmaker name selection in case of duplicate ids in
35+
parametrize.
36+
Thanks `@palaviv`_ for the complete PR (`#1474`_).
3437

3538
*
3639

@@ -39,12 +42,15 @@
3942
.. _@kalekundert: https://github.com/kalekundert
4043
.. _@tareqalayan: https://github.com/tareqalayan
4144
.. _@ceridwen: https://github.com/ceridwen
45+
.. _@palaviv: https://github.com/palaviv
4246

4347
.. _#1428: https://github.com/pytest-dev/pytest/pull/1428
4448
.. _#1444: https://github.com/pytest-dev/pytest/pull/1444
4549
.. _#1441: https://github.com/pytest-dev/pytest/pull/1441
4650
.. _#1454: https://github.com/pytest-dev/pytest/pull/1454
4751
.. _#1351: https://github.com/pytest-dev/pytest/issues/1351
52+
.. _#1468: https://github.com/pytest-dev/pytest/pull/1468
53+
.. _#1474: https://github.com/pytest-dev/pytest/pull/1474
4854

4955
2.9.2.dev1
5056
==========

_pytest/python.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import types
88
import sys
99
import math
10+
import collections
1011

1112
import py
1213
import pytest
@@ -1161,9 +1162,14 @@ def _idvalset(idx, valset, argnames, idfn, ids):
11611162
def idmaker(argnames, argvalues, idfn=None, ids=None):
11621163
ids = [_idvalset(valindex, valset, argnames, idfn, ids)
11631164
for valindex, valset in enumerate(argvalues)]
1164-
if len(set(ids)) < len(ids):
1165-
# user may have provided a bad idfn which means the ids are not unique
1166-
ids = [str(i) + testid for i, testid in enumerate(ids)]
1165+
if len(set(ids)) != len(ids):
1166+
# The ids are not unique
1167+
duplicates = [testid for testid in ids if ids.count(testid) > 1]
1168+
counters = collections.defaultdict(lambda: 0)
1169+
for index, testid in enumerate(ids):
1170+
if testid in duplicates:
1171+
ids[index] = testid + str(counters[testid])
1172+
counters[testid] += 1
11671173
return ids
11681174

11691175
def showfixtures(config):

testing/python/metafunc.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -254,9 +254,9 @@ def ids(val):
254254
(20, KeyError()),
255255
("three", [1, 2, 3]),
256256
], idfn=ids)
257-
assert result == ["0a-a",
258-
"1a-a",
259-
"2a-a",
257+
assert result == ["a-a0",
258+
"a-a1",
259+
"a-a2",
260260
]
261261

262262
@pytest.mark.issue351
@@ -283,10 +283,9 @@ def test_idmaker_with_ids(self):
283283

284284
def test_idmaker_with_ids_unique_names(self):
285285
from _pytest.python import idmaker
286-
result = idmaker(("a", "b"), [(1, 2),
287-
(3, 4)],
288-
ids=["a", "a"])
289-
assert result == ["0a", "1a"]
286+
result = idmaker(("a"), [1,2,3,4,5],
287+
ids=["a", "a", "b", "c", "b"])
288+
assert result == ["a0", "a1", "b0", "c", "b1"]
290289

291290
def test_addcall_and_parametrize(self):
292291
def func(x, y): pass
@@ -850,8 +849,8 @@ def test_function(a, b):
850849
result = testdir.runpytest("-v")
851850
assert result.ret == 1
852851
result.stdout.fnmatch_lines_random([
853-
"*test_function*0a*PASSED",
854-
"*test_function*1a*FAILED"
852+
"*test_function*a0*PASSED",
853+
"*test_function*a1*FAILED"
855854
])
856855

857856
@pytest.mark.parametrize(("scope", "length"),

tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ deps=
1818
[testenv:py26]
1919
commands= py.test --lsof -rfsxX {posargs:testing}
2020
deps=
21-
hypothesis<3.03
21+
hypothesis<3.0
2222
nose
2323
mock<1.1 # last supported version for py26
2424

0 commit comments

Comments
 (0)