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

Session scoped fixture run multiple times when adding fixture via metafunc #5738 #12931

Open
grtdeveloper opened this issue Nov 1, 2024 · 4 comments

Comments

@grtdeveloper
Copy link

grtdeveloper commented Nov 1, 2024

Refering to this ticket : Session scoped fixture run multiple times when adding fixture via metafunc
#5738 : i am trying to achieve the following:

----conftest.py ----
s1_sheet_config, boot_config etc are lists.

def pytest_generate_tests(metafunc):
"""Dynamically parameterize tests based on loaded configurations."""
if 's1_sheet_idx' in metafunc.fixturenames:
metafunc.parametrize("s1_sheet_idx", [s1_sheet_config], indirect=True)

if 'bt_sheet_idx' in metafunc.fixturenames:
    metafunc.parametrize("bt_sheet_idx", [boot_config], indirect=True)

if 'test_idx' in metafunc.fixturenames:
    metafunc.parametrize("test_idx", [test_config], indirect=True)

if 'dt_idx' in metafunc.fixturenames:
    metafunc.parametrize("dt_idx", [dt_config], indirect=True)

---- main.py----

@pytest.mark.parametrize("index", bt_sheet_idx)
def test_boot__sanity(self, index, obj_basic_config=TestBootConfig(), upd_count=TestIncrement(), test_reg=Register()):
......

@pytest.mark.parametrize("index", dt_idx)
def test_dev_sanity(self, index, obj_basic_config=TestBootConfig(), upd_count=TestIncrement(), test_reg=Register()):
.....

I want to execute the complete tests defined in the main.py file for one set of parametrized input first then the reload the new values for the next session and exectue the same tests again for the new set of loaded values.

Test Result should be:
test_boot_sanity [1-1-0] -- PASSED --> Test function for 0 index value
test_boot_sanity [1-1-1] -- PASSED --> Test function for 1 index value
test_boot_sanity [1-2-2] -- PASSED --> Test function for 2 index
:
test_dev_sanity [ 2-2-0] -- PASSED
test_dev_sanity [ 2-2-1] -- PASSED
test_dev_sanity [ 2-2-2] -- PASSED

However, seems only first case is executing... Any help is much appreciated.

@RonnyPfannschmidt
Copy link
Member

With indirect parameterization and objects pasded, pytest test reordering gets potentially confused in case it can't correctly establish parameter identity

There's ongoing tricky refactoring work to get this more stable

@grtdeveloper
Copy link
Author

@RonnyPfannschmidt : so how can we achieve this.

I just want to execute complete test cases with the parameterize input in one session. In next session the parameteize input will change for these test case and they will be executed.

@RonnyPfannschmidt
Copy link
Member

There's too little detail

Based on what I see this shouldn't use parameterize to begin with

@grtdeveloper
Copy link
Author

Requirement is simple : Can we execute the test cases listed in a file which takes parametrize lists as input and need to run for different inputs like a new session.

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