Pymox#
Python mocking on steroids
Release 1.4.1 (What’s new?)
If you’d like more information on why Pymox, check out our summary.
Otherwise, let’s dive right in!
New Elegant Way#
# conftest.py
pytest_plugins = ("mox.testing.pytest_mox",)
# test.py
from mox import expect, stubout
class TestOs:
def test_getcwd(self):
with stubout(os, 'getcwd') as m_getcwd, expect:
m_getcwd.to_be.called_with().and_return('/mox/path')
assert os.getcwd() == '/mox/path'
mox.verify(m_getcwd)
Classic Way#
import mox
import os
class TestOs:
def test_getcwd(self):
m = mox.Mox()
m.stubout(os, 'getcwd')
# calls
os.getcwd().returns('/mox/path')
m.replay_all()
assert os.getcwd() == '/mox/path'
m.verify_all()
if __name__ == '__main__':
import unittest
unittest.main()
Jurassic Way#
import mox
import os
class TestOs(mox.MoxTestBase):
def test_getcwd(self):
self.mox.StubOutWithMock(os, 'getcwd')
# calls
os.getcwd().AndReturn('/mox/path')
self.mox.ReplayAll()
self.assertEqual(os.getcwd(), '/mox/path')
self.mox.VerifyAll()
if __name__ == '__main__':
import unittest
unittest.main()
Basics#
The first chapters shows the basics of Pymox and the features you’ll most likely to use.
Guides#
The following chapters give a broad explanation about Pymox features and how to use them.
Pymox in Practice#
The following chapters deal with considerations of using Pymox in the real world.
- Recipes
- Example 1
- Example 2
- Example 3
- Example 4
- Example 5
- Example 6
- Example 7
- Example 8
- Example 9
- Example 10
- Example 11
- Example 12
- Example 13
- Example 14
- Example 15
- Example 16
- Example 17
- Example 18
- Example 19
- Example 20
- Example 21
- Example 22
- Example 23
- Example 24
- Example 25
- Example 26
- Example 27
- Example 28
- Example 29
- Example 30
- Example 31
- Example 32
- Example 33
- Example 34
- Example 35
- Example 36
- Example 37
- Example 38
- Example 39
- Example 40
- Example 41
- Example 42
- Example 43
- Example 44