Skip to content

Commit c6b578f

Browse files
committed
moving it to its proper module as plugin and created setup.py
1 parent 1ad4d7e commit c6b578f

File tree

3 files changed

+77
-49
lines changed

3 files changed

+77
-49
lines changed

pytest_mock.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import pytest
2+
3+
4+
class MockFixture(object):
5+
def __init__(self):
6+
self._patches = []
7+
self.patch = self._Patcher(self._patches)
8+
9+
def stopall(self):
10+
for p in self._patches:
11+
p.stop()
12+
self._patches[:] = []
13+
14+
class _Patcher(object):
15+
def __init__(self, patches):
16+
self._patches = patches
17+
18+
def object(self, *args, **kwargs):
19+
import mock
20+
21+
p = mock.patch.object(*args, **kwargs)
22+
mocked = p.start()
23+
self._patches.append(p)
24+
return mocked
25+
26+
27+
def multiple(self, *args, **kwargs):
28+
import mock
29+
30+
p = mock.patch.multiple(*args, **kwargs)
31+
mocked = p.start()
32+
self._patches.append(p)
33+
return mocked
34+
35+
36+
def __call__(self, *args, **kwargs):
37+
import mock
38+
39+
p = mock.patch(*args, **kwargs)
40+
mocked = p.start()
41+
self._patches.append(p)
42+
return mocked
43+
44+
45+
@pytest.yield_fixture
46+
def mock():
47+
result = MockFixture()
48+
yield result
49+
result.stopall()

setup.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
from setuptools import setup
2+
3+
4+
setup(
5+
name='pytest-mock',
6+
version='0.1.0',
7+
entry_points={
8+
'pytest11': ['pytest-mock = pytest_mock'],
9+
},
10+
modules=['pytest_mock'],
11+
install_requires=['pytest>=2.3.4', 'mock'],
12+
url='https://github.com/nicoddemus/pytest-mock/',
13+
license='LGPL',
14+
author='Bruno Oliveira',
15+
author_email='[email protected]',
16+
description='Use mock package easily within py.test',
17+
keywords="pytest mock",
18+
classifiers=[
19+
'Development Status :: 3 - Alpha',
20+
'Intended Audience :: Developers',
21+
'License :: OSI Approved :: GNU Lesser General Public License v3 (LGPLv3)',
22+
'Operating System :: OS Independent',
23+
'Programming Language :: Python :: 2.7',
24+
'Programming Language :: Python :: 3',
25+
'Programming Language :: Python :: 3.4',
26+
'Topic :: Software Development :: Testing',
27+
]
28+
)

test_pytest_mock.py

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -2,55 +2,6 @@
22

33
import pytest
44

5-
6-
class MockFixture(object):
7-
def __init__(self):
8-
self._patches = []
9-
self.patch = self._Patcher(self._patches)
10-
11-
def stopall(self):
12-
for p in self._patches:
13-
p.stop()
14-
self._patches[:] = []
15-
16-
class _Patcher(object):
17-
def __init__(self, patches):
18-
self._patches = patches
19-
20-
def object(self, *args, **kwargs):
21-
import mock
22-
23-
p = mock.patch.object(*args, **kwargs)
24-
mocked = p.start()
25-
self._patches.append(p)
26-
return mocked
27-
28-
29-
def multiple(self, *args, **kwargs):
30-
import mock
31-
32-
p = mock.patch.multiple(*args, **kwargs)
33-
mocked = p.start()
34-
self._patches.append(p)
35-
return mocked
36-
37-
38-
def __call__(self, *args, **kwargs):
39-
import mock
40-
41-
p = mock.patch(*args, **kwargs)
42-
mocked = p.start()
43-
self._patches.append(p)
44-
return mocked
45-
46-
47-
@pytest.yield_fixture
48-
def mock():
49-
result = MockFixture()
50-
yield result
51-
result.stopall()
52-
53-
545
class UnixFS(object):
556
@classmethod
567
def rm(cls, filename):

0 commit comments

Comments
 (0)