Skip to content

Commit

Permalink
Refactor runpytest_subprocess code to a function
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoddemus committed Nov 3, 2016
1 parent fae86a6 commit 786f534
Showing 1 changed file with 11 additions and 15 deletions.
26 changes: 11 additions & 15 deletions test_pytest_mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,11 +443,7 @@ def test_foo(mocker):
[pytest]
mock_traceback_monkeypatch = false
""")
if hasattr(testdir, 'runpytest_subprocess'):
result = testdir.runpytest_subprocess()
else:
# pytest 2.7.X
result = testdir.runpytest()
result = runpytest_subprocess(testdir)
assert result.ret == 0


Expand Down Expand Up @@ -483,11 +479,7 @@ def test_foo(mocker):
stub(1, greet='hello')
stub.assert_called_once_with(1, greet='hey')
""")
if hasattr(testdir, 'runpytest_subprocess'):
result = testdir.runpytest_subprocess('--tb=native')
else:
# pytest 2.7.X
result = testdir.runpytest('--tb=native')
result = runpytest_subprocess(testdir, '--tb=native')
assert result.ret == 1
assert 'During handling of the above exception' not in result.stdout.str()
assert 'Differing items:' not in result.stdout.str()
Expand All @@ -508,13 +500,17 @@ def test_foo(mocker):
[pytest]
mock_use_standalone_module = true
""")
if hasattr(testdir, 'runpytest_subprocess'):
result = testdir.runpytest_subprocess()
else:
# pytest 2.7.X
result = testdir.runpytest()
result = runpytest_subprocess(testdir)
assert result.ret == 3
result.stderr.fnmatch_lines([
"*No module named 'mock'*",
])


def runpytest_subprocess(testdir, *args):
"""Testdir.runpytest_subprocess only available in pytest-2.8+"""
if hasattr(testdir, 'runpytest_subprocess'):
return testdir.runpytest_subprocess(*args)
else:
# pytest 2.7.X
return testdir.runpytest(*args)

0 comments on commit 786f534

Please sign in to comment.