34

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 ) )
sazr
  • 24,984
  • 66
  • 194
  • 362
  • 2
    You are getting the error because that path doesn't exist, as planned, also there is no need for `== 1` – jamylak Apr 13 '13 at 00:43
  • I didn't downvote but I'm guessing it was because your case is too localized, which doesn't warrant a downvote, only a close vote – jamylak Apr 13 '13 at 00:49
  • 2
    @jamylak attempting to assert that a file exists is very localised indeed lol, treading into unknown territory, I should be in the history books aye – sazr Apr 13 '13 at 00:50
  • Except in your case your assertion is already correct so the problem must be something else – jamylak Apr 13 '13 at 00:53
  • 3
    @jamylak I found this discussion while myself writing a Unit Test that checks if deleting files works properly. In web applications and probably many others, too, it's often relevant that files are properly deleted. I wonder why writing a test about that is such a localized and special thing. – Philipp Zedler Feb 25 '15 at 10:38
  • @PhilippZedler I didn't say that. The question is localized because you are already asserting a file exists so I was just wondering what are you asking? – jamylak Feb 25 '15 at 10:46
  • LOL at localized, local to what? Humans that wanna check if a file exists? Man I hope someone come up with a competing and very similar site soon – codyc4321 Oct 30 '15 at 21:52
  • Yay sweet vindication...only took 2 and a half years but I'll take it. Glad this question is still alive and relevant years later. You could say this question is almost...international...global even? ;) – sazr Oct 31 '15 at 03:26

1 Answers1

10

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.

Michael Hoffman
  • 32,526
  • 7
  • 64
  • 86