def test_push_image_raises_if_error_encountered(monkeypatch): storage = Docker(base_image="python:3.6") client = MagicMock() client.push.return_value = [ {"progress": "test"}, {"error": "you know nothing jon snow"}, ] monkeypatch.setattr("docker.APIClient", MagicMock(return_value=client)) with pytest.raises(InterruptedError, match="you know nothing jon snow"): storage.push_image(image_name="test", image_tag="test")
def test_push_image(capsys, monkeypatch): storage = Docker(base_image="python:3.6") client = MagicMock() client.push.return_value = [{"progress": "test", "status": "100"}] monkeypatch.setattr("docker.APIClient", MagicMock(return_value=client)) storage.push_image(image_name="test", image_tag="test") captured = capsys.readouterr() printed_lines = [line for line in captured.out.split("\n") if line != ""] assert any("100 test\r" in line for line in printed_lines)