Simple testing of Salt modules

After spending some time trying to learn testing and later how to test Salt modules I felt that I need to summarise what I have done and what I missed.

Testing Salt modules seems to require the following python packages:


When I tried to run tests without the salt-factories plugin I only received the following error:

FAILED _modules/ - NameError: name '__salt__' is not defined

Since I started using Tox for testing I had forgotten to add pytest-salt-factories as a dependency for the test python environment.

def test_parse_rc_conf() -> None:
    rc_contents = 'ifconfig_vtnet0="inet"\nifconfig_vlan123="vlandev vtnet0 vlan 123 description \'UnitTesting\''
    with patch.dict(
            "file.replace": MagicMock(return_value=True),
            "": mock_open(read_data=rc_contents),
            "file.grep": MagicMock(return_value={"stdout": rc_contents})
        expected = {
            'vlan123': '"vlandev vtnet0 vlan 123 description \'UnitTesting\'', 
            'vtnet0': '"inet"'
        assert interfacemod.parse_rc_conf() == expected