<filename>tests/test_keys.py
import testinfra.utils.ansible_runner

testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
    '.molecule/ansible_inventory').get_hosts('all')


def test_number_of_keys(File, Sudo):
    f_root = File('/root/.ssh/authorized_keys')
    f_johnd = File('/home/johnd/.ssh/authorized_keys')
    root_keys = sum(1 for line in f_root.content_string.splitlines())
    johnd_keys = sum(1 for line in f_johnd.content_string.splitlines())

    assert f_root.exists
    assert f_root.contains('ssh-rsa <KEY>')  # noqa: E501
    assert root_keys == 3
    assert f_johnd.exists
    assert f_johnd.contains('ssh-rsa <KEY>')  # noqa: E501
    assert f_johnd.contains('ssh-rsa <KEY>')  # noqa: E501
    assert johnd_keys == 4

<filename>tests/test_keys.py
import testinfra.utils.ansible_runner

testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
    '.molecule/ansible_inventory').get_hosts('all')


def test_number_of_keys(File, Sudo):
    f_root = File('/root/.ssh/authorized_keys')
    f_johnd = File('/home/johnd/.ssh/authorized_keys')
    root_keys = sum(1 for line in f_root.content_string.splitlines())
    johnd_keys = sum(1 for line in f_johnd.content_string.splitlines())

    assert f_root.exists
    assert f_root.contains('ssh-rsa <KEY>')  # noqa: E501
    assert root_keys == 3
    assert f_johnd.exists
    assert f_johnd.contains('ssh-rsa <KEY>')  # noqa: E501
    assert f_johnd.contains('ssh-rsa <KEY>')  # noqa: E501
    assert johnd_keys == 4

# noqa: E501 # noqa: E501 # noqa: E501