diff --git a/testsuite/expect/test17.51 b/testsuite/expect/test17.51
index ea2e5818ec64f4097db48281f105f24f54b86af0..4e76c3a9445cfb80c6529752ea90bab8a770b551 100755
--- a/testsuite/expect/test17.51
+++ b/testsuite/expect/test17.51
@@ -121,14 +121,15 @@ send_user "\n---Checking sbatch uses mcs-label only for some jobs (ondemand mode
 #
 # Change the slurm.conf MCSparameters and MCSPlugin
 #
-exec $bin_sed -i /MCS/d $config_path/slurm.conf
-exec $bin_sed -i /mcs/d $config_path/slurm.conf
-exec $bin_sed -i /PrivateData/d $config_path/slurm.conf
-exec $bin_echo MCSPlugin=mcs/user >> $config_path/slurm.conf
+exec $bin_sed -i /^\s*MCSPlugin\s*=/Id $config_path/slurm.conf
+exec $bin_sed -i /^\s*MCSParameters\s*=/Id $config_path/slurm.conf
+exec $bin_sed -i /^\s*PrivateData\s*=/Id $config_path/slurm.conf
+exec $bin_echo -e "\nMCSPlugin=mcs/user" >> $config_path/slurm.conf
 exec $bin_echo MCSParameters=ondemand,select,privatedata >> $config_path/slurm.conf
 exec $bin_echo PrivateData=jobs,nodes >> $config_path/slurm.conf
 update_conf
 
+
 #
 # verify slurm conf parameters MCS
 #
@@ -333,14 +334,15 @@ cancel_job $job_id
 # test with enforced
 #
 send_user "\n---Checking sbatch uses mcs-label with all jobs (enforced mode)---\n"
-exec $bin_sed -i /MCS/d $config_path/slurm.conf
-exec $bin_sed -i /mcs/d $config_path/slurm.conf
-exec $bin_sed -i /PrivateData/d $config_path/slurm.conf
-exec $bin_echo MCSPlugin=mcs/user >> $config_path/slurm.conf
+exec $bin_sed -i /^\s*MCSPlugin\s*=/Id $config_path/slurm.conf
+exec $bin_sed -i /^\s*MCSParameters\s*=/Id $config_path/slurm.conf
+exec $bin_sed -i /^\s*PrivateData\s*=/Id $config_path/slurm.conf
+exec $bin_echo -e "\nMCSPlugin=mcs/user" >> $config_path/slurm.conf
 exec $bin_echo MCSParameters=enforced,noselect,privatedata >> $config_path/slurm.conf
 exec $bin_echo PrivateData=jobs,nodes >> $config_path/slurm.conf
 update_conf
 
+
 ###### Check that sbatch uses mcs-label=user ######
 send_user "\n---Checking sbatch uses mcs-label=user---\n"
 
diff --git a/testsuite/expect/test17.52 b/testsuite/expect/test17.52
index 09fc317dba91c851b92f4c17b517d756bc12cac6..6a6ccc66b6c219b5ff0009fb10cefdd2863e1447 100755
--- a/testsuite/expect/test17.52
+++ b/testsuite/expect/test17.52
@@ -136,14 +136,15 @@ expect {
 	}
 }
 
-exec $bin_sed -i /MCS/d $config_path/slurm.conf
-exec $bin_sed -i /mcs/d $config_path/slurm.conf
-exec $bin_sed -i /PrivateData/d $config_path/slurm.conf
-exec $bin_echo MCSPlugin=mcs/group >> $config_path/slurm.conf
+exec $bin_sed -i /^\s*MCSPlugin\s*=/Id $config_path/slurm.conf
+exec $bin_sed -i /^\s*MCSParameters\s*=/Id $config_path/slurm.conf
+exec $bin_sed -i /^\s*PrivateData\s*=/Id $config_path/slurm.conf
+exec $bin_echo -e "\nMCSPlugin=mcs/group" >> $config_path/slurm.conf
 exec $bin_echo MCSParameters=ondemand,select,privatedata:$groups_name >> $config_path/slurm.conf
 exec $bin_echo PrivateData=jobs,nodes >> $config_path/slurm.conf
 update_conf
 
+
 #
 # verify slurm conf parameters MCS
 #
@@ -358,14 +359,15 @@ cancel_job $job_id
 # test with enforced
 #
 send_user "\n---Checking sbatch uses mcs-label with all jobs (enforced mode)---\n"
-exec $bin_sed -i /MCS/d $config_path/slurm.conf
-exec $bin_sed -i /mcs/d $config_path/slurm.conf
-exec $bin_sed -i /PrivateData/d $config_path/slurm.conf
-exec $bin_echo MCSPlugin=mcs/group >> $config_path/slurm.conf
+exec $bin_sed -i /^\s*MCSPlugin\s*=/Id $config_path/slurm.conf
+exec $bin_sed -i /^\s*MCSParameters\s*=/Id $config_path/slurm.conf
+exec $bin_sed -i /^\s*PrivateData\s*=/Id $config_path/slurm.conf
+exec $bin_echo -e "\nMCSPlugin=mcs/group" >> $config_path/slurm.conf
 exec $bin_echo MCSParameters=enforced,noselect,privatedata:$groups_name >> $config_path/slurm.conf
 exec $bin_echo PrivateData=jobs,nodes >> $config_path/slurm.conf
 update_conf
 
+
 ###### Check that sbatch uses mcs-label=group ######
 send_user "\n---Checking sbatch uses mcs-label=group---\n"