fake_cache = type('FakeCache', (), {'get': lambda self, key: None, 'set': lambda self, key, value: None})()
Testing Patterns

Meaning

Creates a simple mock cache object with get and set methods that do nothing and return None, serving as a test double or placeholder.

Primary Function

Provides a dummy cache object for testing or placeholder purposes.

Communicative Purpose

Signals that the object is a test double/cache stub that intentionally ignores inputs and returns no effect.

Pattern

type(class_name, (), {'method_name': lambda self, *args: default_return})

Core Structure

type('FakeCache', (), {'get': lambda self, key: None, 'set': lambda self, key, value: None})

Função primária

Provides a dummy cache object for testing or placeholder purposes.

Propósito comunicativo

Signals that the object is a test double/cache stub that intentionally ignores inputs and returns no effect.

Situações de gatilho

Used when a real cache is not needed, e.g., during unit testing to isolate dependencies, or as a placeholder in prototype code.

Contextos

Unit testing Test doubles Stubbing dependencies Prototyping Mocking external caches

Padrão

type(class_name, (), {'method_name': lambda self, *args: default_return})

Estrutura central

type('FakeCache', (), {'get': lambda self, key: None, 'set': lambda self, key, value: None})

Slots de substituição

class_name method_name:get method_name:set return_value:None

Colocados típicos

  • FakeCache mock stub test mock object unittest dependency injection

Substituições comuns

  • unittest.mock.Mock collections.defaultdict simple dict lambda: None

Erros comuns

Failing to include self parameter in lambda Returning a value when None is expected causing test failures Forgetting to bind methods to instance leading to TypeError Using mutable default arguments incorrectly

Similar / contraste

types.SimpleNamespace collections.namedtuple unittest.mock.MagicMock hand‑crafted class with explicit methods

Interferências

May be mistaken for a functional cache, leading to silent bugs if caching behavior is expected.

Família do chunk

  • test doubles / mock objects

Nuance

The get and set methods deliberately ignore their arguments and always return None, making the object a no‑op stub.

Efeito pragmático

Communicates intentional absence of caching behavior, signaling a test double or placeholder to readers of the code.

Dica de memória

Fake cache that does nothing

Nota

Useful for quick stubs; for more complex behavior consider unittest.mock.Mock or a real caching library like functools.lru_cache.

Upgrade path

Replace with unittest.mock.Mock for flexible behavior, or use functools.lru_cache for a lightweight real cache.

Frequência: LowFormulaicidade: Semi-fixedTipo de construção: Dynamic class creation using type() with lambda methodsPrioridade de aquisição: Passive recognitionPrioridade de output: OutputTag de espaçamento: Medium-term

Log in to save chunks.