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 in last test and fixtures more than a function #126

Closed
ShurikMen opened this issue Sep 17, 2020 · 2 comments
Closed

Flaky in last test and fixtures more than a function #126

ShurikMen opened this issue Sep 17, 2020 · 2 comments

Comments

@ShurikMen
Copy link

ShurikMen commented Sep 17, 2020

If last test mark as flaky and it failed, then for each rerun all fixtures above function are restarted too.

import pytest


@pytest.fixture(scope="session", autouse=True)
def fixture_session():
    print("fixture_session start")


@pytest.fixture(scope="module", autouse=True)
def fixture_module():
    print("fixture_module start")


@pytest.fixture(scope="class", autouse=True)
def fixture_class():
    print("fixture_class start")


class TestIt:
    @pytest.mark.flaky(reruns=3, delay=1)
    def test_stuff(self):
        assert False

Result:

pytest -sv --no-summary --disable-warnings test_params.py 
=========================================================================================================== test session starts ===========================================================================================================
platform linux -- Python 3.8.5, pytest-6.0.1, py-1.9.0, pluggy-0.13.1 -- /home/lolik/Testing/pytest/venv/bin/python
cachedir: .pytest_cache
rootdir: /home/lolik/Testing/pytest, configfile: pytest.ini
plugins: dependency-0.5.1, allure-pytest-2.8.18, ordering-0.6, rerunfailures-9.1
collected 1 item                                                                                                                                                                                                                          

test_params.py::TestIt::test_stuff fixture_session start
fixture_module start
fixture_class start
RERUN
test_params.py::TestIt::test_stuff fixture_session start
fixture_module start
fixture_class start
RERUN
test_params.py::TestIt::test_stuff fixture_session start
fixture_module start
fixture_class start
RERUN
test_params.py::TestIt::test_stuff fixture_session start
fixture_module start
fixture_class start
FAILED

This happens when nextitem is none in pytest_runtest_protocol. If you add an empty test to the end, the fixtures will not be restarted.

class TestIt:
    @pytest.mark.flaky(reruns=3, delay=1)
    def test_stuff(self):
        assert False

    def test_empty(self):
        pass

Result:

pytest -sv --no-summary --disable-warnings test_params.py 
=========================================================================================================== test session starts ===========================================================================================================
platform linux -- Python 3.8.5, pytest-6.0.1, py-1.9.0, pluggy-0.13.1 -- /home/lolik/Testing/pytest/venv/bin/python
cachedir: .pytest_cache
rootdir: /home/lolik/Testing/pytest, configfile: pytest.ini
plugins: dependency-0.5.1, allure-pytest-2.8.18, ordering-0.6, rerunfailures-9.1
collected 2 items                                                                                                                                                                                                                         

test_params.py::TestIt::test_stuff fixture_session start
fixture_module start
fixture_class start
RERUN
test_params.py::TestIt::test_stuff RERUN
test_params.py::TestIt::test_stuff RERUN
test_params.py::TestIt::test_stuff FAILED
test_params.py::TestIt::test_empty PASSED

How correct is this decision?

def pytest_runtest_protocol(item, nextitem):
    <.....>
    while need_to_run:
        item.execution_count += 1
        item.ihook.pytest_runtest_logstart(nodeid=item.nodeid, location=item.location)
        reports = runtestprotocol(item, nextitem=nextitem or item, log=False)
@ShurikMen ShurikMen changed the title Incorrect work with parameterization Flaky with parameterization and class scope fixtures Sep 17, 2020
@ShurikMen ShurikMen changed the title Flaky with parameterization and class scope fixtures Flaky in last test and fixtures more than a function Sep 17, 2020
@icemac
Copy link
Contributor

icemac commented Sep 18, 2020

Maybe this issue is similar to #51.

@ShurikMen
Copy link
Author

Yes, it's the same problem.

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

2 participants