Skip to content

Instantly share code, notes, and snippets.

@blueset
Created January 30, 2018 07:00
Show Gist options
  • Save blueset/e51ef7d06ba21dba97272b3334bf75a7 to your computer and use it in GitHub Desktop.
Save blueset/e51ef7d06ba21dba97272b3334bf75a7 to your computer and use it in GitHub Desktop.

./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