@@ -96,6 +96,44 @@ def test_run_command_line_config(mocker, cfg, argument, value, tmp_path):
9696 assert session [argument ] == value
9797
9898
99+ def test_run_session_name (mocker , cfg , tmp_path ):
100+ """Check that `session_name` overrides the auto-generated name."""
101+ mocker .patch .object (esmvalcore .config , "CFG" , cfg )
102+ session = cfg .start_session .return_value
103+
104+ program = ESMValTool ()
105+ recipe_file = "/path/to/recipe_test.yml"
106+ config_dir = tmp_path / "config"
107+ config_dir .mkdir (parents = True , exist_ok = True )
108+
109+ mocker .patch .object (program , "_get_recipe" , return_value = Path (recipe_file ))
110+ mocker .patch .object (program , "_run" )
111+
112+ program .run (recipe_file , session_name = "result" , config_dir = config_dir )
113+
114+ assert session .session_name == "result"
115+ # Check that the session name is not passed to the cfg
116+ for call in cfg .nested_update .call_args_list :
117+ assert "session_name" not in call .args [0 ]
118+
119+
120+ def test_run_no_session_name (mocker , cfg , tmp_path ):
121+ """Check that the session name is left untouched by default."""
122+ mocker .patch .object (esmvalcore .config , "CFG" , cfg )
123+
124+ program = ESMValTool ()
125+ recipe_file = "/path/to/recipe_test.yml"
126+ config_dir = tmp_path / "config"
127+ config_dir .mkdir (parents = True , exist_ok = True )
128+
129+ mocker .patch .object (program , "_get_recipe" , return_value = Path (recipe_file ))
130+ mocker .patch .object (program , "_run" )
131+
132+ program .run (recipe_file , config_dir = config_dir )
133+
134+ assert "session_name" not in cfg .start_session .return_value .__dict__
135+
136+
99137@pytest .mark .parametrize ("search_data" , ["quick" , "complete" ])
100138def test_run (mocker , session , search_data ):
101139 session ["search_data" ] = search_data
0 commit comments