I have in my conftest.py
a container (dependency injector) which "patches" over my prod config.yaml
with a test.yaml
. This is initialised in the conftest.py
module, like so:
@pytest.fixture(scope="session")
def test_initialize():
test_container = initialize(test_yaml_dir)
return test_container
@pytest.fixture(scope="session")
def test_instantiate_mgr(test_initialize):
test_id = "123456"
test_name = test_initialize.config.env.stage_name()
test_m = Manager(
id=test_id,
stage_name=test_name,
)
return test_tm
This calls the parameters in the test.yaml
(not the config.yaml), and is verified to work.
In my test1.py
def _test_get_match_url(test_instantiate_mgr)
assert test_instantiate_mgr._get_match_url().get("dept") == "https://invalid/again_invalid_1"
So the returned value in test_instantiate_mgr._get_match_url().get("dept")
is the one given in my config.yaml
, and not the one in the test.yaml
And the _get_match_url()
in a different module (manager.py):
manager.py
# set above
container = initialize(prod_yaml)
container.config()
...
def _get_match_url(self, env) -> dict:
base_url = container.config.urls.base_url()
stage = env
if stage == "a":
return {"dept1": base_url + container.config.urls.dept1_s(),
"dept2": base_url + container.config.urls.dept2_s()}
elif stage == "b":
return {"dept1": base_url + container.config.urls.dept1(),
"dept2": base_url + container.config.urls.dept2()}
I had expected that the conftest.py fixture would use the test.yaml everwhere, but it is only used correctly for part of the test. However the call is not used in the _get_match_url method. How can I get the test to use the correct yaml (i.e. the test.yaml), and not the config.yaml?