我想生成不重复的唯一 ID。我尝试使用st.uuids()
.
这是我的代码
class MyTest(<class that inherits from unittest.TestCase>)
@hypothesis.seed(0)
@hypothesis.settings(derandomize=True)
@hypothesis.setting(use_coverage=False)
@hypothesis.given(st.uuids())
def test(self, test_id):
logging.info('test_id %s', test_id)
logging.info('self.ids %s', self.ids)
if test_id in self.ids:
logging.info('SHOULD NOT BE HERE')
else:
logging.info('HAPPY')
self.ids.append(test_id)
但是,我重复了 1 次。关于如何避免重复的任何提示?
test_id 5bc8fbbc-bde5-c099-4164-d8399f767c45
self.ids [UUID('e3e70682-c209-4cac-629f-6fbed82c07cd'),
UUID('1ee77147-c7be-894d-5073-79c36d3c338d'),
UUID('734007f9-e3b1-3a59-bac6-78e47a6e8c0f'),
UUID('97343ee7-03f6-c7c0-d787-3a75e0040c6d'),
UUID('12193edd-6aac-c6b6-8caf-d66c89075de6'),
UUID('ea37c9e0-a3f9-3fe5-0b68-afbaab69828e'),
UUID('e13a37b0-f328-3835-4a40-cfc1142acbf7'),
UUID('36a3a379-28ca-876f-6b68-1fc4502323be'),
UUID('cbf97494-2dae-a0f6-43a5-5203d7fdc239'),
UUID('94012b2d-1221-006b-266c-7dcefecc417e'),
UUID('e05fccb4-9d81-b03f-4f0c-7c859a0af299'),
UUID('c6148cd8-b446-bc4f-7fea-3b29b7b93ee5'),
UUID('cd613e30-d8f1-6adf-91b7-584a2265b1f5'),
UUID('d95bafc8-f2a4-d27b-dcf4-bb99f4bea973'),
UUID('5af6e118-6344-2432-9707-6fb276cfc8bf'),
UUID('c1a4bbe2-f5bc-beed-3a7c-be792b90ac94'),
UUID('01457085-dc53-6b6a-b47f-3aefd7768cc6'),
UUID('6beb5a8d-f4b1-3663-a3e3-c900e848b602'),
UUID('21636369-8b52-9b4a-97b7-50923ceb3ffd'),
UUID('b8a1abcd-1a69-16c7-4da4-f9fc3c6da5d7'),
UUID('5bc8fbbc-bde5-c099-4164-d8399f767c45')]
SHOULD NOT BE HERE
奇怪的是,我可以在日志语句上方的日志语句中看到该 id。
我想知道@cacheable
or@defines_strategy_with_reusable_values
是否与它有关
https://github.com/HypothesisWorks/hypothesis/blob/cedbafe52934e5f710be41c51044388ef3047850/hypothesis-python/src/hypothesis/strategies.py#L1868