Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?

./test.py

from unittest import TestCase
from unittest.mock import patch, Mock
from foo import FooModule

class DemoTest(TestCase):
    @classmethod
    def setUpClass(cls):
        patch("foo.client.Client").start()

    def test_craft_message(self):
        c = FooModule(0)
        c.ping()

    @classmethod
    def tearDownClass(cls):
        patch.stopall()

./foo/__init__.py

from .client import Client

class FooModule:
    v = -1

    def __init__(self, n):
        self.v = n
        self.client = Client(self) 
    
    def ping(self):
        self.client.ping(2048)

./foo/client.py

class Client:
    def __init__(self, foo_module):
        self.foo = foo_module
    
    def ping(self, n):
        return n / self.foo.v
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.