reruns condition evaluates not in real time
- version: 10.0
- code
retryBool = True
@pytest.mark.flaky(condition=retryBool,reruns=2)
def test_demo():
retryBool = False
assert False
I found that if I set the mark like the above code, It can't stop retry when after the first run. It shows that the condition does not evaluate in real time but before the case was run.
But I think it's better if the condition evaluates in real time, because it let me able to control the retry on runtime. For example, if the number of failed cases reaches a certain number, then retry the following failed cases.
And the@pytest.mark.skipif(condition="bool",reason="xxx") evaluates in real time.
To change the value of the global variable you have to declare it global, otherwise you create a new independent local variable in your test function:
retryBool = True
@pytest.mark.flaky(condition=retryBool,reruns=2)
def test_demo():
global retryBool
retryBool = False
assert False
See https://docs.python.org/3/reference/simple_stmts.html#grammar-token-global-stmt for details about global.
Sorry, my Fault. I forgot to add global. But after declaring it global , it also doesn't work.

And I refactor this with my PR