I'm running my first unit test on this function contained in a module called updater
:
import logging
import subprocess
logger = logging.getLogger(__name__)
def update_oncourt():
return_code = subprocess.run(['perl', 'oncourt_update.pl']).returncode
if return_code == 0:
logger.info('Updated OnCourt with latest data')
return True
else:
logger.warning(f'OnCourt update errored with code: {return_code}')
return False
I'm using the following unittest
method:
from unittest import main, TestCase
from unittest.mock import patch
import updater
class TestStuff(TestCase):
def test_update_oncourt(self):
with patch('updater.subprocess.run') as mocked_run:
mocked_run.return_value.returncode == 0
return_code = updater.update_oncourt()
mocked_run.assert_called_with(['perl', 'oncourt_update.pl'])
self.assertTrue(return_code)
if __name__ == '__main__':
main()
I realise this is very simplistic but I'm just trying to understand the basics at this stage.
I'm expecting return_code
to be True
and it's False
:
self.assertTrue(return_code)
AssertionError: False is not true