Skip to content

Commit 48db809

Browse files
committed
Refactor runpytest_subprocess code to a function
1 parent 7d7deea commit 48db809

File tree

1 file changed

+11
-15
lines changed

1 file changed

+11
-15
lines changed

test_pytest_mock.py

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -443,11 +443,7 @@ def test_foo(mocker):
443443
[pytest]
444444
mock_traceback_monkeypatch = false
445445
""")
446-
if hasattr(testdir, 'runpytest_subprocess'):
447-
result = testdir.runpytest_subprocess()
448-
else:
449-
# pytest 2.7.X
450-
result = testdir.runpytest()
446+
result = runpytest_subprocess(testdir)
451447
assert result.ret == 0
452448

453449

@@ -483,11 +479,7 @@ def test_foo(mocker):
483479
stub(1, greet='hello')
484480
stub.assert_called_once_with(1, greet='hey')
485481
""")
486-
if hasattr(testdir, 'runpytest_subprocess'):
487-
result = testdir.runpytest_subprocess('--tb=native')
488-
else:
489-
# pytest 2.7.X
490-
result = testdir.runpytest('--tb=native')
482+
result = runpytest_subprocess(testdir, '--tb=native')
491483
assert result.ret == 1
492484
assert 'During handling of the above exception' not in result.stdout.str()
493485
assert 'Differing items:' not in result.stdout.str()
@@ -508,13 +500,17 @@ def test_foo(mocker):
508500
[pytest]
509501
mock_use_standalone_module = true
510502
""")
511-
if hasattr(testdir, 'runpytest_subprocess'):
512-
result = testdir.runpytest_subprocess()
513-
else:
514-
# pytest 2.7.X
515-
result = testdir.runpytest()
503+
result = runpytest_subprocess(testdir)
516504
assert result.ret == 3
517505
result.stderr.fnmatch_lines([
518506
"*No module named 'mock'*",
519507
])
520508

509+
510+
def runpytest_subprocess(testdir, *args):
511+
"""Testdir.runpytest_subprocess only available in pytest-2.8+"""
512+
if hasattr(testdir, 'runpytest_subprocess'):
513+
return testdir.runpytest_subprocess(*args)
514+
else:
515+
# pytest 2.7.X
516+
return testdir.runpytest(*args)

0 commit comments

Comments
 (0)