I am creating automation framework where in few parameters I have kept in a separate JSON file. I have written the below fixture which would load the data from the JSON file in conftest.py.
import json
@pytest.fixture(scope='session')
def get_config_values():
with open('./Resources/config.json') as f:
config_values = json.load(f)
return config_values
I have kept the scope as session so that I do not need to load them for every test class. I am intending to use this return value in all the test classes which are in the below way
@pytest.mark.usefixtures("get_config_values")
class TestConf:
def test_conf_test1(self):
print(f"Test for user a")
print(self.config_values["a"])
def test_conf_test2(self):
print(f"Test for user b")
print(self.config_values["b"])
I am unable to use the return value in the the tests. I have tried below ways-
print(self.config_values["b"])
print(get_config_values["b"])
Please can someone help me how can we use session fixture return values in tests. Or if there is any better way to achieve this.
def test_conf_test(self, config_values):
? See e.g. docs.pytest.org/en/stable/…