Skip to content

Commit 277720d

Browse files
committed
Ensure we never have conflicting test names.
1 parent d98ab06 commit 277720d

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

tests.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import contextlib
44
import glob
55
import io
6+
import itertools
67
import json
78
import os
89
import pprint
@@ -72,6 +73,7 @@ def add_test_methods(test_class):
7273
continue
7374

7475
validating, _ = os.path.splitext(os.path.basename(filename))
76+
id = itertools.count(1)
7577

7678
with open(filename) as test_file:
7779
data = json.load(test_file)
@@ -84,8 +86,9 @@ def add_test_methods(test_class):
8486
test["valid"],
8587
)
8688

87-
test_name = "test_%s_%s" % (
89+
test_name = "test_%s_%s_%s" % (
8890
validating,
91+
next(id),
8992
re.sub(r"[\W ]+", "_", test["description"]),
9093
)
9194

@@ -98,6 +101,7 @@ def add_test_methods(test_class):
98101
a_test
99102
)
100103

104+
assert not hasattr(test_class, test_name), test_name
101105
setattr(test_class, test_name, a_test)
102106

103107
return test_class

0 commit comments

Comments
 (0)