def test_main__should_not_patch_poetry__when_pip_is_not_found( mocker, poetry_mock): # mock sys.modules to make `import pip` raise an exception mocker.patch.dict(sys.modules, {'pip': None}) # call main pooetry.main() # assert poetry is not patched assert poetry_mock.installation.pip_installer.PipInstaller.run != pooetry.run_patch
def test_main__should_patch_poetry__when_pip_and_poetry_are_supported_versions( pip_mock, poetry_mock): # change pip version to 19.0.3 pip_mock.__version__ = "19.0.3" # change poetry version to 0.12.17 poetry_mock.__version__ = "0.12.17" # call main pooetry.main() # assert poetry is patched assert poetry_mock.installation.pip_installer.PipInstaller.run == pooetry.run_patch
def test_main__should_not_patch_poetry__when_poetry_is_unsupported_version( pip_mock, poetry_mock): # change pip version to 19.0.3 pip_mock.__version__ = "19.0.3" # change poetry version to 1.0.0b1 poetry_mock.__version__ = "1.0.0b1" # call main pooetry.main() # assert poetry is not patched assert poetry_mock.installation.pip_installer.PipInstaller.run != pooetry.run_patch
def test_main__should_return_error__when_poetry_is_not_found( mocker, sys_exit_mock): # patch shutil.which to return None mocker.patch('shutil.which').return_value = None # set sys.exit mock to return an exception sys_exit_mock.side_effect = [Exception()] # call main with pytest.raises(Exception): pooetry.main() # assert sys.exit was called with error about poetry not found sys_exit_mock.assert_called_once() args, _ = sys_exit_mock.call_args msg = args[0] assert "poetry" in msg and "not found" in msg