提交 1b30a73f authored 作者: Pierre Luc Carrier's avatar Pierre Luc Carrier

Fix decorator according to feedback

上级 4d18ca43
...@@ -385,9 +385,7 @@ class AttemptManyTimes: ...@@ -385,9 +385,7 @@ class AttemptManyTimes:
# need to be called before any attempts to execute the test in # need to be called before any attempts to execute the test in
# case it relies on data randomly generated in the class' setup() # case it relies on data randomly generated in the class' setup()
# method. # method.
if (len(args) == 1 and hasattr(args[0], "_testMethodName") and if (len(args) == 1 and hasattr(args[0], "_testMethodName")):
hasattr(args[0], "setUp")):
test_in_class = True test_in_class = True
class_instance = args[0] class_instance = args[0]
else: else:
...@@ -403,29 +401,34 @@ class AttemptManyTimes: ...@@ -403,29 +401,34 @@ class AttemptManyTimes:
try: try:
# Attempt to make the test use the current seed # Attempt to make the test use the current seed
config.unittests.rseed = current_seed config.unittests.rseed = current_seed
if test_in_class: if test_in_class and hasattr(class_instance, "setUp"):
class_instance.setUp() class_instance.setUp()
fct(*args, **kwargs) fct(*args, **kwargs)
n_success += 1 n_success += 1
if current_seed not in [None, "random"]:
current_seed = str(int(current_seed) + 1)
if n_success == self.n_req_successes: if n_success == self.n_req_successes:
config.unittests.rseed = original_seed
break break
except: except Exception:
n_fail += 1 n_fail += 1
if current_seed not in [None, "random"]:
current_seed = str(int(current_seed) + 1)
# If there is not enough attempts remaining to achieve the # If there is not enough attempts remaining to achieve the
# required number of successes, propagate the original # required number of successes, propagate the original
# exception # exception
if n_fail + self.n_req_successes > self.n_attempts: if n_fail + self.n_req_successes > self.n_attempts:
config.unittests.rseed = original_seed
raise raise
finally:
# Clean up after the test
config.unittests.rseed = original_seed
if test_in_class and hasattr(class_instance, "tearDown"):
class_instance.tearDown()
# Update the current_seed
config.unittests.rseed = original_seed
if current_seed not in [None, "random"]:
current_seed = str(int(current_seed) + 1)
return attempt_multiple_times return attempt_multiple_times
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论