Unit Testing: Assert that a file/path exists

Question:

I am attempting to create a regression test for my Installer. The regression test is a script written in Python. The test checks that the correct files have been installed in the correct place.

Is there a way to assert that a file/folder exists? I am getting a AssertionError error for the following code:

assert os.path.exists(LOCAL_INSTALL_DIR) == 1

Why am I getting this error and how can I fix it? My function:

def check_installation_files_exist():
    assert os.path.exists(LOCAL_INSTALL_DIR) == 1
    assert os.path.exists(INSTALL_DIR) == 1
    correct_install_files = normalise_file_names( os.listdir( LOCAL_INSTALL_DIR ) )
    installed_files       = normalise_file_names( os.listdir( INSTALL_DIR ) )
Asked By: sazr

||

Answers:

The path described by LOCAL_INSTALL_DIR either does not exist, is a broken symbolic link, or you do not have permission to stat() it.

Answered By: Michael Hoffman
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.