Skip to content
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

Flaky fail on final test invokes pytest session fixture #128

Open
robertrmartinez opened this issue Oct 5, 2017 · 2 comments
Open

Flaky fail on final test invokes pytest session fixture #128

robertrmartinez opened this issue Oct 5, 2017 · 2 comments

Comments

@robertrmartinez
Copy link

I have a pytest fixture which runs at the "session" scope. This fixture starts a local web server, and initiates a sauce labs connection. Upon teardown, it stops the server and closes the sauce connection.

When the final test of my test run is a "flaky" test and fails, it acts as if the session is over and calls my fixture tear down.

Then, the flaky test is rerun, which invokes the session fixture once again.

I would like the session fixture to only be called once obviously due to the overhead of having to spin up the server and start the sauce connection again.

This could be a pytest issue, but I figured I would open an issue here as well to see if there is any suggestions or solutions in the works?

@AlexDubrovsky
Copy link

AlexDubrovsky commented Feb 25, 2018

I have a similar issue with the following example:
`import pytest
from flaky import flaky

class TestFlaky():

@classmethod
def setup_class(cls):
    print("In setup class")

@flaky(max_runs=5, min_passes=1)
@pytest.mark.parametrize('param', [1, 2, 3])
def test1(self, param):
    print("In test1, param={}".format(param))
    assert param == 1

@classmethod
def teardown_class(cls):
    print("In teardown class")`

When the last test fails, the teardown is triggered, but then the whole sequence of setup->test->teardown is triggered again for the remaining attempts, only for the last test (with param=3).

@Sebelino
Copy link

Same issue here. A dumb workaround for now is to create a non-flaky dummy test at the end of the module/session scope:

@flaky
def my_last_real_test():
    ...

def test_nonflaky_dummy():  # Exists as a workaround for https://github.com/box/flaky/issues/128
    pass

abdosi added a commit to abdosi/sonic-swss that referenced this issue Aug 11, 2020
currently pytest will call session/module tear-down before flaky
can retry the test. Session/Module will be setup again to run retry
count.

Because of above behaviour when last test fail for given module
all the logs are lost for all test-case upto that point since when
tear down is called dvs container is destroyed and to run retry instance
DVS container is setup up again and logs only belonging to this instance
of run are captured and overwrite all previous logs.

Workaround to have default dummy pass test case at end always so we
avoid module tear-down and setup again.

Signed-off-by: Abhishek Dosi <abdosi@microsoft.com>
abdosi added a commit to sonic-net/sonic-swss that referenced this issue Aug 13, 2020
#1395)

* As reported by this issue PR#box/flaky#128
currently pytest will call session/module tear-down before flaky
can retry the test. Session/Module will be setup again to run retry
count.

Because of above behaviour when last test fail for given module
all the logs are lost for all test-case upto that point since when
tear down is called dvs container is destroyed and to run retry instance
DVS container is setup up again and logs only belonging to this instance
of run are captured and overwrite all previous logs.

Workaround to have default dummy pass test case at end always so we
avoid module tear-down and setup again.

Signed-off-by: Abhishek Dosi <abdosi@microsoft.com>

* Fix formating

Signed-off-by: Abhishek Dosi <abdosi@microsoft.com>

* Added 2 space/blank lines as per review comment

Signed-off-by: Abhishek Dosi <abdosi@microsoft.com>

* Updated README with flaky issue mention.

Signed-off-by: Abhishek Dosi <abdosi@microsoft.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants