Assertion functions for the filesystem

These functions make it easy to check the state of files and directories. When the assertion is not true, they provide informative error messages.

testpath.assert_path_exists(path, msg=None)

Assert that something exists at the given path.

testpath.assert_not_path_exists(path, msg=None)

Assert that nothing exists at the given path.

testpath.assert_isfile(path, follow_symlinks=True, msg=None)

Assert that path exists and is a regular file.

With follow_symlinks=True, the default, this will pass if path is a symlink to a regular file. With follow_symlinks=False, it will fail in that case.

testpath.assert_not_isfile(path, follow_symlinks=True, msg=None)

Assert that path exists but is not a regular file.

With follow_symlinks=True, the default, this will fail if path is a symlink to a regular file. With follow_symlinks=False, it will pass in that case.

testpath.assert_isdir(path, follow_symlinks=True, msg=None)

Assert that path exists and is a directory.

With follow_symlinks=True, the default, this will pass if path is a symlink to a directory. With follow_symlinks=False, it will fail in that case.

testpath.assert_not_isdir(path, follow_symlinks=True, msg=None)

Assert that path exists but is not a directory.

With follow_symlinks=True, the default, this will fail if path is a symlink to a directory. With follow_symlinks=False, it will pass in that case.

Assert that path exists and is a symlink.

If to is specified, also check that it is the target of the symlink.

Assert that path exists but is not a symlink.