Skip to content

Commit

Permalink
Skip tests which require assertion rewriting when it is disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoddemus committed Feb 16, 2018
1 parent ed8cdde commit 3e929f9
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
7 changes: 6 additions & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
1.7.1
-----

* Fix ``mock`` requirements in Python 2. Thanks `@ghisvail`_ for the report.
* Fix ``mock`` requirements in Python 2. Thanks `@ghisvail`_ for the report (`#101`_).

**Internal change**

* Some tests in ``pytest-mock``'s suite are skipped if assertion rewriting is disabled (`#102`_).

.. _@ghisvail: https://github.com/ghisvail
.. _#101: https://github.com/pytest-dev/pytest-mock/issues/101
.. _#102: https://github.com/pytest-dev/pytest-mock/issues/102

1.7.0
-----
Expand Down
16 changes: 16 additions & 0 deletions test_pytest_mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,19 @@
reason='could not make work on pypy')


@pytest.fixture
def needs_assert_rewrite(pytestconfig):
"""
Fixture which skips requesting test if assertion rewrite is disabled (#102)
Making this a fixture to avoid acessing pytest's config in the global context.
"""
option = pytestconfig.getoption('assertmode')
if option != 'rewrite':
pytest.skip('this test needs assertion rewrite to work but current option '
'is "{}"'.format(option))


class UnixFS(object):
"""
Wrapper to os functions to simulate a Unix file system, used for testing
Expand Down Expand Up @@ -375,6 +388,7 @@ def test_assert_called_once_with_wrapper(mocker):
stub.assert_called_once_with("foo")


@pytest.mark.usefixtures('needs_assert_rewrite')
def test_assert_called_args_with_introspection(mocker):
stub = mocker.stub()

Expand All @@ -390,6 +404,7 @@ def test_assert_called_args_with_introspection(mocker):
stub.assert_called_once_with(*wrong_args)


@pytest.mark.usefixtures('needs_assert_rewrite')
def test_assert_called_kwargs_with_introspection(mocker):
stub = mocker.stub()

Expand Down Expand Up @@ -510,6 +525,7 @@ def runpytest_subprocess(testdir, *args):
return testdir.runpytest(*args)


@pytest.mark.usefixtures('needs_assert_rewrite')
def test_detailed_introspection(testdir):
"""Check that the "mock_use_standalone" is being used.
"""
Expand Down

0 comments on commit 3e929f9

Please sign in to comment.