Skip to content

Commit 2ca46e4

Browse files
authored
Merge pull request #105 from nicoddemus/assert-rewrite-tests
Skip tests which require assertion rewriting when it is disabled
2 parents ed8cdde + 5689c61 commit 2ca46e4

File tree

5 files changed

+31
-2
lines changed

5 files changed

+31
-2
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ htmlcov/
3131
.tox/
3232
.coverage
3333
.cache
34+
.pytest_cache
3435
nosetests.xml
3536
coverage.xml
3637

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ jobs:
1818
include:
1919
- python: '3.6'
2020
env: TOXENV=linting
21+
- python: '3.6'
22+
env: TOXENV=norewrite
2123
- stage: deploy
2224
python: '3.6'
2325
install: pip install -U setuptools setuptools_scm

CHANGELOG.rst

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
1.7.1
22
-----
33

4-
* Fix ``mock`` requirements in Python 2. Thanks `@ghisvail`_ for the report.
4+
* Fix ``mock`` requirements in Python 2. Thanks `@ghisvail`_ for the report (`#101`_).
5+
6+
**Internal change**
7+
8+
* Some tests in ``pytest-mock``'s suite are skipped if assertion rewriting is disabled (`#102`_).
59

610
.. _@ghisvail: https://github.com/ghisvail
711
.. _#101: https://github.com/pytest-dev/pytest-mock/issues/101
12+
.. _#102: https://github.com/pytest-dev/pytest-mock/issues/102
813

914
1.7.0
1015
-----

test_pytest_mock.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,19 @@
1313
reason='could not make work on pypy')
1414

1515

16+
@pytest.fixture
17+
def needs_assert_rewrite(pytestconfig):
18+
"""
19+
Fixture which skips requesting test if assertion rewrite is disabled (#102)
20+
21+
Making this a fixture to avoid acessing pytest's config in the global context.
22+
"""
23+
option = pytestconfig.getoption('assertmode')
24+
if option != 'rewrite':
25+
pytest.skip('this test needs assertion rewrite to work but current option '
26+
'is "{}"'.format(option))
27+
28+
1629
class UnixFS(object):
1730
"""
1831
Wrapper to os functions to simulate a Unix file system, used for testing
@@ -375,6 +388,7 @@ def test_assert_called_once_with_wrapper(mocker):
375388
stub.assert_called_once_with("foo")
376389

377390

391+
@pytest.mark.usefixtures('needs_assert_rewrite')
378392
def test_assert_called_args_with_introspection(mocker):
379393
stub = mocker.stub()
380394

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

392406

407+
@pytest.mark.usefixtures('needs_assert_rewrite')
393408
def test_assert_called_kwargs_with_introspection(mocker):
394409
stub = mocker.stub()
395410

@@ -510,6 +525,7 @@ def runpytest_subprocess(testdir, *args):
510525
return testdir.runpytest(*args)
511526

512527

528+
@pytest.mark.usefixtures('needs_assert_rewrite')
513529
def test_detailed_introspection(testdir):
514530
"""Check that the "mock_use_standalone" is being used.
515531
"""

tox.ini

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[tox]
2-
envlist = py{27,34,35,36}-pytest{30,31,32},linting
2+
envlist = py{27,34,35,36}-pytest{30,31,32,33,34},linting,norewrite
33

44
[testenv]
55
passenv = USER USERNAME
@@ -9,9 +9,14 @@ deps =
99
pytest31: pytest~=3.1
1010
pytest32: pytest~=3.2
1111
pytest33: pytest~=3.3
12+
pytest34: pytest~=3.4
1213
commands =
1314
coverage run --append --source=pytest_mock.py -m pytest test_pytest_mock.py
1415

16+
[testenv:norewrite]
17+
commands =
18+
pytest test_pytest_mock.py --assert=plain -ra
19+
1520
[testenv:linting]
1621
skip_install=True
1722
deps =

0 commit comments

Comments
 (0)