Skip to content

Instantly share code, notes, and snippets.

@rishabh-ink
Last active March 23, 2019 22:54
Show Gist options
  • Save rishabh-ink/cd0cc6437dcd431c436ab2689b695e05 to your computer and use it in GitHub Desktop.
Save rishabh-ink/cd0cc6437dcd431c436ab2689b695e05 to your computer and use it in GitHub Desktop.
Of pytest and lru_cache in Python
$ tox
...
... # content snipped
...
# The test passes for the 1st parameterized run when ordinary_object='quill'
(Pdb) ordinary_object
'quill'
(Pdb) list
with mock.patch(
'levitation.cast_spell',
autospec=True,
) as patched_cast_spell:
> import pdb; pdb.set_trace()
(Pdb) levitate.cache_info()
CacheInfo(hits=0, misses=0, maxsize=2, currsize=0)
(Pdb) continue
...
... # content snipped
...
# The test passes for the 2nd parameterized run when ordinary_object='cushion'
(Pdb) ordinary_object
'cushion'
(Pdb) list
with mock.patch(
'levitation.cast_spell',
autospec=True,
) as patched_cast_spell:
> import pdb; pdb.set_trace()
(Pdb) levitate.cache_info()
CacheInfo(hits=1, misses=0, maxsize=2, currsize=1)
(Pdb) continue
...
... # content snipped
...
# The test fails for the 3nd parameterized run when ordinary_object='cauldron'
(Pdb) ordinary_object
'cauldron'
(Pdb) list
with mock.patch(
'levitation.cast_spell',
autospec=True,
) as patched_cast_spell:
> import pdb; pdb.set_trace()
(Pdb) levitate.cache_info()
CacheInfo(hits=2, misses=0, maxsize=2, currsize=2)
(Pdb) continue
...
AssertionError: Expected 'cast_spell' to be called once. Called 0 times.
...
...
... # content snipped
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment