Skip to content

How to run assert on all files in a directory during testinfra test #3032

Answered by hunter86bg
hunter86bg asked this question in General
Discussion options

You must be logged in to vote

So far I managed to run it like this (replaced dir and filenames):

def test_ownership_multidir(host):
    somedir = host.file('/opt/somedir/')
    assert somedir.is_directory

    
    for filename in somedir.listdir():
        fullfile = '/opt/somedir/' + filename


        assert host.file(fullfile).user == 'root'
        assert host.file(fullfile).group == 'root'

        if filename == "somefile":
            assert oct(host.file(fullfile).mode) == '0o4555'
        else:
            assert oct(host.file(fullfile).mode) == '0o755'

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by hunter86bg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
1 participant