Skip to content

Instantly share code, notes, and snippets.

View elnygren's full-sized avatar

el3ng elnygren

  • Helsinki, Finland
View GitHub Profile
@elnygren
elnygren / patch.py
Created August 8, 2021 12:15
Patching in Python with pytest using monkeypatch and requests_mock
import requests
API_URL = "https://example.com" # often imported from settings
#
# Code
#
def get_user_with_org(id: str):
"""Gets a User object with the User's Organisation"""
@elnygren
elnygren / test.py
Created August 8, 2021 13:43
Testing DI enabled Python code.
import pytest
from unittest.mock import MagicMock
@pytest.fixture()
def patch_user_service():
"""
reusable patcher,
handy when there are lots of test cases
"""
user_connector = MagicMock()