diff --git a/setup.py b/setup.py index ef7b5b1..d136f95 100755 --- a/setup.py +++ b/setup.py @@ -118,7 +118,7 @@ setup( setup_requires=[ 'setuptools_scm', ], - tests_require=['tox', 'pytest', 'pytest-cov', 'nose', 'scripttest', 'mock', 'hypothesis'], + tests_require=['tox', 'pytest', 'pytest-cov', 'pytest-mock', 'nose', 'scripttest', 'mock', 'hypothesis'], cmdclass={'test': Tox}, entry_points={ 'console_scripts': [ diff --git a/test/test_printer_file.py b/test/test_printer_file.py index bce9a0e..4d1b188 100644 --- a/test/test_printer_file.py +++ b/test/test_printer_file.py @@ -15,7 +15,7 @@ from __future__ import unicode_literals import six -import mock +import pytest from hypothesis import given from hypothesis.strategies import text @@ -27,21 +27,22 @@ else: mock_open_call = '__builtin__.open' @given(path=text()) -@mock.patch(mock_open_call) -@mock.patch('escpos.escpos.Escpos.__init__') -def test_load_file_printer(mock_escpos, mock_open, path): +def test_load_file_printer(mocker, path): """test the loading of the file-printer""" + mock_escpos = mocker.patch('escpos.escpos.Escpos.__init__') + mock_open = mocker.patch(mock_open_call) printer.File(devfile=path) assert mock_escpos.called mock_open.assert_called_with(path, "wb") @given(txt=text()) -@mock.patch.object(printer.File, 'device') -@mock.patch(mock_open_call) -@mock.patch('escpos.escpos.Escpos.__init__') -def test_auto_flush(mock_escpos, mock_open, mock_device, txt): +def test_auto_flush(mocker, txt): """test auto_flush in file-printer""" + mock_escpos = mocker.patch('escpos.escpos.Escpos.__init__') + mock_open = mocker.patch(mock_open_call) + mock_device = mocker.patch.object(printer.File, 'device') + p = printer.File(auto_flush=False) # inject the mocked device-object p.device = mock_device @@ -56,10 +57,11 @@ def test_auto_flush(mock_escpos, mock_open, mock_device, txt): @given(txt=text()) -@mock.patch.object(printer.File, 'device') -@mock.patch(mock_open_call) -def test_flush_on_close(mock_open, mock_device, txt): +def test_flush_on_close(mocker, txt): """test flush on close in file-printer""" + mock_open = mocker.patch(mock_open_call) + mock_device = mocker.patch.object(printer.File, 'device') + p = printer.File(auto_flush=False) # inject the mocked device-object p.device = mock_device diff --git a/tox.ini b/tox.ini index 362f2a6..bed3686 100644 --- a/tox.ini +++ b/tox.ini @@ -8,6 +8,7 @@ deps = nose mock pytest pytest-cov + pytest-mock hypothesis commands = py.test --cov escpos