-
Notifications
You must be signed in to change notification settings - Fork 84
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixtures marked (scope='session') are run on every re-run #51
Comments
@dangercrow Thanks for the report. Just for completeness: Which pytest version do you use? I could reproduce the behaviour you reported. It seems that pytest produces a complete teardown if there are no more items available for execution. When I use the following example, setup and teardown seem to be only called once. import pytest
@pytest.fixture(scope="session")
def example_fixture():
print("\nSetup")
yield
print("\nTeardown")
fail_twice = (x for x in [False, False, True])
@pytest.mark.flaky(reruns=1)
def test_example_fixture_1(example_fixture):
assert next(fail_twice)
def test_stay_true():
assert True The respective result of
Could you maybe comment on that, whether your failing test case was always the last one in your test setup? I am not completely sure, whether it is possible to fix this easily as |
@dangercrow Do you have comments on that issue anymore? I see that this seems to be a problem, but without further confirmation it is hard to work on that. |
Ta for the ping. pytest version is 3.1.2 It seems your test case illustrates the issue quite well - I see the same behaviour as you! |
I have had the same issue as well. I have a session fixture which opens and closes a tunnel to Sauce Labs, This 'bug' causes the final test in my suite to close the session, then once again re-open it for the rerun. Causes a good minute or two overhead each time the Tests before the final test work as expected. So, it looks like pytest sees the final test has just run, says "Okay lets tear this session down", and after that rerun triggers. I haven't looked into the code, but seems like pytest needs to have visibility of a rerun before it makes the decision to initiate a tear down? Thanks for all of your hard work! |
@dangercrow @robertrmartinez it seems that we have another issue reported that is related to this one (#56) I will try to have a look into this issue over the next weeks. |
I am observing the same behavior. |
Hello, I am observing the same behavior. |
I actually would argue that this is the expected and correct behavior. In certain cases when re-running flaky tests, you may want to start from scratch as the flakyness may be in the setup of the tests or the setup of the tests may in some way cause flakyness down the line. This looks like a scope that |
@sallner I am also experiencing the same with pytest 5.3.5 & pytest-rerunfailures==7.0 |
One idea is to set a global variable when the fixture runs and checking the variable before executing. Since session fixtures are being re-run, state may be reset between re-runs. There must be state somewhere that persists though. pytest-dev/pytest#2461 |
[READY] Workaround for pytest-dev/pytest-rerunfailures#51
For what it's worth this happens for |
As of recently-ish the hack with a trivial test at the end of the file doesn't cut it any more. I attempted to roll back both pytest and rerunfailures, to no avail. The attempted pull request is here and you can see repeated I'm hoping someone will have an idea, else I'll have to rewrite the test suite in unittest... and I really don't want to do that. |
Any progress on this? This is quite a major bug for my setup :-/ |
@henzef Sorry, there is no progress on this. If someone wants to volunteer in the investigation and/or in fixing this issue: any help is welcome. |
version: 10.3 |
Im observing the same behavior with
|
Observing same behaviour, fixed using this
|
I would expect that session fixtures are run once per session - but it seems if a
flaky
test reruns, it will run session scoped fixtures' teardown code, and then their setup again.This can result in costly setup/teardown being unnecessarily rerun, and also seems to go against the whole point of labelling the fixture
session
Reproduction:
Running with
pytest -s -v ...
I get:The text was updated successfully, but these errors were encountered: