You can only use the keyword with ... :
with context-manager and os.chdir()
just isn't a Context Manager.
You can simply do something like (if you don't need working dir to be restored afterwards)
files = ['mklvars.csh','mklvars.sh']
os.chdir('/opt/intel/mkl/bin')
print('testing')
if all([os.path.isfile(f) for f in files]):
print("Installation succesful")
else:
print("not succesful")
But if you need the current working directory to be restored at the end, there are different options you can use.
One example (with https://github.com/jaraco/path):
from path import Path
# Changing the working directory:
files = ['mklvars.csh','mklvars.sh']
with Path('/opt/intel/mkl/bin'):
print('testing')
if all([os.path.isfile(f)for f in files]):
print("Installation succesful")
else:
print("not succesful")
Other solutions: checkout this Question
For further reading on context-managers: