How to check list of environment variable in python?
You can group the messages and corresponding exit codes into a dict, and then iterate over that one:

def check_mandatory_envs():
    exit_codes = {
        "ENVCONTEST_1" :125,
        "ENVCONTEST_2" :126,
        "ENVVIRTEST_3" :127,
        "ENVVIRTEST_4" :128,
        "ENVPATHTEST_5":129,
        "ENVPATHTEST_6":130,
    }
    for variable, code in exit_codes.items():
        if variable not in os.environ:
            exit(code)


If the order of the iteration is important and you are on python before 3.6, you canuse a collections.OrderedDict or a list of tuples, without the .items() call