Last active
April 11, 2019 21:19
-
-
Save samdoran/cf2789ae7cbfce2aec6859e90816dea6 to your computer and use it in GitHub Desktop.
Example pytest unit test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
from ansible.module_utils.facts.hardware import sunos | |
def test_sunos_get_uptime_facts(mocker): | |
kstat_output = '\nunix:0:system_misc:boot_time\t1548249689\n' | |
module_mock = mocker.patch('ansible.module_utils.basic.AnsibleModule') | |
module = module_mock() | |
module.run_command.return_value = (0, kstat_output, '') | |
inst = sunos.SunOSHardware(module) | |
expected = int(time.time()) - 1548249689 | |
result = inst.get_uptime_facts() | |
assert expected == result['uptime_seconds'] |
I updated the example with working code. I'm not sure exactly about the real output since I don't have a system to test on. If you feel it's necessary, we could also add more output examples and iterate through them.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
tried this one
pytest run output
i'm getting
with
test/units/module_utils/facts/hardware/test_linux_get_cpu_info.py
as well
but
ansible-test units --tox ...
worksPS: installed 'mock' packages