'PYTEST - Is it possible to create the same fixtures more than one time?
I have some parameters coming from a JSON file, and some fixtures in my conftest.py
I would like to iterate all the option scenarios from my list and create my fixtures each time accordingly.
I know that I can use the "params" option in the @pytest.fixture definition but this option doesn't appropriate to cover my specific scenarios.
For example:
I have two parameters in two scenarios (servers come from the same level of the JSON file):
scenario number one:
servers = ["path1", "path2"]
users = [("user_name1", "pw1"), ("user_name2", "pw2")]
scenario number two:
servers = ["path3"]
users = [("user_name3", "pw3")]
If I transfer to @pytest.fixture(params = [["path1", "path2","path3"])
and to another @pytest.fixture(params = [("user_name1", "pw1"), ("user_name2", "pw2"), ("user_name3", "pw3")]
I will collect 9 tests and I would like to collect only 3 tests (2 tests from the above first scenario and 1 test from the above second scenario.
I tried to iterate in my conftest.py and read each level from my Json file and I succeeded to reach all my three options ( If I print them I received three messages).
The problem is that I can not succeeded to create my two fixtures more than one time.
Pytest take only the last scenario option and collect only 1 test.
Pytest doesn't allowed to iterate and create fixtures dynamically.
Do you know how to fix it?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|